fmt: fix alignment of struct init fields (#22025)

This commit is contained in:
yuyi 2024-08-11 14:11:24 +08:00 committed by GitHub
parent 99da5726db
commit c51d30bf53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
671 changed files with 18817 additions and 18787 deletions

View file

@ -16,13 +16,13 @@ pub fn (match_expr &MatchExpr) desugar() Expr {
op := if cond in [Ident, SelectorExpr] { token.Token.key_is } else { token.Token.eq }
c := InfixExpr{
lhs: match_expr.expr
op: op
op: op
rhs: cond
}
if branch_cond !is EmptyExpr {
branch_cond = InfixExpr{
lhs: branch_cond
op: .logical_or
op: .logical_or
rhs: c
}
} else {
@ -30,7 +30,7 @@ pub fn (match_expr &MatchExpr) desugar() Expr {
}
}
if_expr2 := IfExpr{
cond: branch_cond
cond: branch_cond
stmts: branch.stmts
}
if i == 0 {
@ -61,7 +61,7 @@ pub fn (or_expr &OrExpr) desugar() Expr {
name: 'len'
}
}
op: .gt
op: .gt
rhs: or_expr.expr.expr
}
stmts: [ExprStmt{
@ -75,7 +75,7 @@ pub fn (or_expr &OrExpr) desugar() Expr {
return IfExpr{
cond: InfixExpr{
lhs: or_expr.expr
op: .eq
op: .eq
rhs: BasicLiteral{
kind: .key_true
}

View file

@ -34,8 +34,8 @@ fn build_tabs(tabs_len int) []string {
pub fn new_gen(prefs &pref.Preferences) &Gen {
unsafe {
return &Gen{
pref: prefs
out: strings.new_builder(1000)
pref: prefs
out: strings.new_builder(1000)
indent: -1
}
}

View file

@ -30,7 +30,7 @@ mut:
pub fn Parser.new(prefs &pref.Preferences) &Parser {
return &Parser{
pref: unsafe { prefs }
pref: unsafe { prefs }
scanner: scanner.new_scanner(prefs, .normal)
// scanner: scanner.new_scanner(prefs, .skip_interpolation)
}
@ -129,9 +129,9 @@ pub fn (mut p Parser) parse_file(filename string, mut file_set token.FileSet) as
}
return ast.File{
attributes: attributes
mod: mod
name: filename
imports: imports
mod: mod
name: filename
imports: imports
// decls: decls
stmts: top_stmts
}
@ -219,7 +219,7 @@ fn (mut p Parser) stmt() ast.Stmt {
p.next()
expr := p.expr(.lowest)
stmt := ast.AssertStmt{
expr: expr
expr: expr
extra: if p.tok == .comma {
p.next()
p.expr(.lowest)
@ -236,7 +236,7 @@ fn (mut p Parser) stmt() ast.Stmt {
label := p.lit()
p.expect_semi()
return ast.FlowControlStmt{
op: op
op: op
label: label
}
} else {
@ -393,7 +393,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
match p.tok {
.char, .key_false, .key_true, .number {
lhs = ast.BasicLiteral{
kind: p.tok
kind: p.tok
value: p.lit()
}
}
@ -444,8 +444,8 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
return ast.Type(typ)
}
lhs = ast.FnLiteral{
typ: typ
stmts: p.block()
typ: typ
stmts: p.block()
captured_vars: captured_vars
}
}
@ -463,7 +463,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
if p.tok == .lpar {
p.next()
lhs = ast.KeywordOperator{
op: op
op: op
exprs: [p.expr_or_type(.lowest)]
}
p.expect(.rpar)
@ -479,7 +479,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
op := p.tok()
p.expect(.lpar)
lhs = ast.KeywordOperator{
op: op
op: op
exprs: [p.expr(.lowest)]
}
p.expect(.rpar)
@ -490,7 +490,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
expr := p.expr(.lowest)
p.expect(.comma)
lhs = ast.KeywordOperator{
op: op
op: op
exprs: [expr, p.expr(.lowest)]
}
p.expect(.rpar)
@ -498,7 +498,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
.key_go, .key_spawn {
op := p.tok()
lhs = ast.KeywordOperator{
op: op
op: op
exprs: [p.expr(.lowest)]
}
}
@ -540,9 +540,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
}
p.exp_lcbr = exp_lcbr
return ast.LockExpr{
lock_exprs: lock_exprs
lock_exprs: lock_exprs
rlock_exprs: rlock_exprs
stmts: p.block()
stmts: p.block()
}
}
.key_struct {
@ -623,7 +623,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
lhs = ast.MapInitExpr{
keys: keys
vals: vals
pos: pos
pos: pos
}
}
.lsbr {
@ -688,7 +688,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
} else if exprs2.len == 1 {
lhs = ast.Type(ast.ArrayFixedType{
elem_type: elem_type
len: exprs2[0]
len: exprs2[0]
})
} else {
// TODO: use same error message as typ() `expect(.rsbr)`
@ -709,9 +709,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
}
p.next()
lhs = ast.ArrayInitExpr{
typ: lhs
typ: lhs
init: init
pos: pos
pos: pos
}
}
// `[2]type`
@ -728,7 +728,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
else {
lhs = ast.ArrayInitExpr{
exprs: exprs
pos: pos
pos: pos
}
for i := 1; i < exprs_arr.len; i++ {
exprs2 := exprs_arr[i]
@ -737,7 +737,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
p.error('invalid index expr')
}
lhs = ast.IndexExpr{
lhs: lhs
lhs: lhs
expr: exprs2[0]
}
}
@ -767,11 +767,11 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
}
p.next()
lhs = ast.ArrayInitExpr{
typ: lhs
typ: lhs
init: init
cap: cap
len: len
pos: pos
cap: cap
len: len
pos: pos
}
}
// `[]type`
@ -794,7 +794,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
exprs: exprs
// NOTE: indicates fixed `!`
len: ast.PostfixExpr{
op: .not
op: .not
expr: ast.empty_expr
}
pos: pos
@ -803,7 +803,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
} else {
lhs = ast.ArrayInitExpr{
exprs: exprs
pos: pos
pos: pos
}
}
}
@ -827,16 +827,16 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
}
p.exp_lcbr = exp_lcbr
branches << ast.MatchBranch{
cond: cond
cond: cond
stmts: p.block()
pos: branch_pos
pos: branch_pos
}
p.expect_semi()
if p.tok == .key_else {
p.next()
branches << ast.MatchBranch{
stmts: p.block()
pos: branch_pos
pos: branch_pos
}
p.expect_semi()
}
@ -844,9 +844,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// rcbr
p.next()
lhs = ast.MatchExpr{
expr: expr
expr: expr
branches: branches
pos: match_pos
pos: match_pos
}
}
.key_atomic, .key_mut, .key_shared, .key_static, .key_volatile {
@ -924,8 +924,8 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
if p.tok.is_prefix() {
// NOTE: just use .highest for now, later we might need to define for each op
lhs = ast.PrefixExpr{
pos: p.pos
op: p.tok()
pos: p.pos
op: p.tok()
expr: p.expr(.highest)
}
} else {
@ -945,7 +945,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
p.next()
lhs = ast.AsCastExpr{
expr: lhs
typ: p.expect_type()
typ: p.expect_type()
}
}
// call | cast
@ -960,9 +960,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// fncall()! (Propagate Result) | fncall()? (Propagate Option)
if p.tok in [.not, .question] {
lhs = ast.CallExpr{
lhs: lhs
lhs: lhs
args: args
pos: pos
pos: pos
}
// lhs = ast.PostfixExpr{
// expr: lhs
@ -974,26 +974,26 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// definitely a cast
if lhs is ast.Type {
lhs = ast.CastExpr{
typ: lhs
typ: lhs
expr: args[0]
pos: pos
pos: pos
}
}
// work this out after type checking
else {
lhs = ast.CallOrCastExpr{
lhs: lhs
lhs: lhs
expr: args[0]
pos: pos
pos: pos
}
}
}
// definitely a call (0 args, or more than 1 arg)
else {
lhs = ast.CallExpr{
lhs: lhs
lhs: lhs
args: args
pos: pos
pos: pos
}
}
}
@ -1012,8 +1012,8 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// gated, even if followed by `(` we know it's `arr#[fn_idx]()` and not `fn[int]()`
// println('HERE')
lhs = ast.IndexExpr{
lhs: lhs
expr: p.range_expr(p.expr(.lowest))
lhs: lhs
expr: p.range_expr(p.expr(.lowest))
is_gated: true
}
p.expect(.rsbr)
@ -1041,21 +1041,21 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// multiple exprs | `fn[GenericStruct[int]]()` nested generic args
if exprs.len > 1 || expr is ast.GenericArgs {
lhs = ast.GenericArgs{
lhs: lhs
lhs: lhs
args: exprs
}
}
// `ident[ident]()` this will be determined at a later stage by checking lhs
else if expr in [ast.Ident, ast.SelectorExpr] {
lhs = ast.GenericArgOrIndexExpr{
lhs: lhs
lhs: lhs
expr: expr
}
}
// `array[0]()` we know its an index
else {
lhs = ast.IndexExpr{
lhs: lhs
lhs: lhs
expr: expr
}
}
@ -1067,12 +1067,12 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// if p.exp_pt && expr in [ast.GenericArgs, ast.Ident, ast.SelectorExpr] && p.tok in [.comma, .rsbr] {
if p.exp_pt && expr in [ast.GenericArgs, ast.Ident, ast.SelectorExpr] {
lhs = ast.GenericArgs{
lhs: lhs
lhs: lhs
args: exprs
}
} else {
lhs = ast.IndexExpr{
lhs: lhs
lhs: lhs
expr: expr
}
}
@ -1096,7 +1096,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// NOTE: should this require parens?
else if p.tok in [.not, .question] {
lhs = ast.PostfixExpr{
op: p.tok()
op: p.tok()
expr: lhs
}
} else if p.tok == .key_or {
@ -1104,9 +1104,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
pos := p.pos
p.next()
lhs = ast.OrExpr{
expr: lhs
expr: lhs
stmts: p.block()
pos: pos
pos: pos
}
}
// range
@ -1114,7 +1114,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
// p.log('ast.RangeExpr')
// no need to continue
return ast.RangeExpr{
op: p.tok()
op: p.tok()
start: lhs
// if range ever gets used in other places, wont be able to check .rsbr
end: if p.tok == .rsbr { ast.empty_expr } else { p.expr(.lowest) }
@ -1129,7 +1129,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
pos := p.pos
op := p.tok()
lhs = ast.InfixExpr{
op: op
op: op
lhs: lhs
// `x in y` allow range for this case, eg. `x in 1..10`
rhs: if op == .key_in {
@ -1145,7 +1145,7 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
}
} else if p.tok.is_postfix() {
lhs = ast.PostfixExpr{
op: p.tok()
op: p.tok()
expr: lhs
}
} else {
@ -1161,9 +1161,9 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
fn (mut p Parser) range_expr(lhs_expr ast.Expr) ast.Expr {
if p.tok in [.dotdot, .ellipsis] {
return ast.RangeExpr{
op: p.tok()
op: p.tok()
start: lhs_expr
end: if p.tok == .rsbr { ast.empty_expr } else { p.expr(.lowest) }
end: if p.tok == .rsbr { ast.empty_expr } else { p.expr(.lowest) }
}
}
return lhs_expr
@ -1313,7 +1313,7 @@ fn (mut p Parser) attributes() []ast.Attribute {
// name = 'unsafe'
value = ast.Ident{
name: 'unsafe'
pos: p.pos
pos: p.pos
}
}
// TODO: properly
@ -1350,8 +1350,8 @@ fn (mut p Parser) attributes() []ast.Attribute {
}
}
attributes << ast.Attribute{
name: name
value: value
name: name
value: value
comptime_cond: comptime_cond
}
if p.tok == .semicolon {
@ -1396,7 +1396,7 @@ fn (mut p Parser) asm_stmt() ast.AsmStmt {
fn (mut p Parser) assign_stmt(lhs []ast.Expr) ast.AssignStmt {
return ast.AssignStmt{
pos: p.pos
op: p.tok()
op: p.tok()
lhs: lhs
rhs: p.expr_list()
}
@ -1409,13 +1409,13 @@ fn (mut p Parser) comptime_expr() ast.Expr {
.key_if {
return ast.ComptimeExpr{
expr: p.if_expr(true)
pos: pos
pos: pos
}
}
else {
return ast.ComptimeExpr{
expr: p.expr(.lowest)
pos: p.pos
pos: p.pos
}
}
}
@ -1469,9 +1469,9 @@ fn (mut p Parser) for_stmt() ast.ForStmt {
// p.expect(.key_in)
p.next()
init = ast.ForInStmt{
key: expr
key: expr
value: expr2
expr: p.expr(.lowest)
expr: p.expr(.lowest)
}
} else if p.tok == .lcbr {
// `for x in y {`
@ -1479,7 +1479,7 @@ fn (mut p Parser) for_stmt() ast.ForStmt {
if mut expr is ast.InfixExpr && expr.op == .key_in {
init = ast.ForInStmt{
value: expr.lhs
expr: expr.rhs
expr: expr.rhs
}
}
// `for x < y {`
@ -1519,9 +1519,9 @@ fn (mut p Parser) for_stmt() ast.ForStmt {
stmts := p.block()
p.expect_semi()
return ast.ForStmt{
init: init
cond: cond
post: post
init: init
cond: cond
post: post
stmts: stmts
}
}
@ -1598,9 +1598,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
else_expr = p.if_expr(is_comptime)
}
return ast.IfExpr{
cond: cond
cond: cond
else_expr: else_expr
stmts: stmts
stmts: stmts
}
}
@ -1637,10 +1637,10 @@ fn (mut p Parser) import_stmt() ast.ImportStmt {
}
// p.log('ast.ImportStmt: $name as $alias')
return ast.ImportStmt{
name: name
alias: alias
name: name
alias: alias
is_aliased: is_aliased
symbols: symbols
symbols: symbols
}
}
@ -1663,7 +1663,7 @@ fn (mut p Parser) directive() ast.Directive {
}
// p.next()
return ast.Directive{
name: name
name: name
value: value
}
}
@ -1680,7 +1680,7 @@ fn (mut p Parser) const_decl(is_public bool) ast.ConstDecl {
p.expect(.assign)
value := p.expr(.lowest)
fields << ast.FieldInit{
name: name
name: name
value: value
}
p.expect(.semicolon)
@ -1694,7 +1694,7 @@ fn (mut p Parser) const_decl(is_public bool) ast.ConstDecl {
}
return ast.ConstDecl{
is_public: is_public
fields: fields
fields: fields
}
}
@ -1728,11 +1728,11 @@ fn (mut p Parser) fn_decl(is_public bool, attributes []ast.Attribute) ast.FnDecl
receiver_pos := p.pos
receiver = ast.Parameter{
name: p.expect_name()
typ: p.expect_type()
typ: p.expect_type()
// name: receiver_name
// typ: receiver_type
is_mut: is_mut
pos: receiver_pos
pos: receiver_pos
}
p.expect(.rpar)
// operator overload
@ -1748,8 +1748,8 @@ fn (mut p Parser) fn_decl(is_public bool, attributes []ast.Attribute) ast.FnDecl
p.next()
}
receiver2 := ast.Parameter{
name: p.expect_name()
typ: p.expect_type()
name: p.expect_name()
typ: p.expect_type()
is_mut: is_mut
}
_ = receiver2
@ -1802,15 +1802,15 @@ fn (mut p Parser) fn_decl(is_public bool, attributes []ast.Attribute) ast.FnDecl
p.expect(.semicolon)
return ast.FnDecl{
attributes: attributes
is_public: is_public
is_method: is_method
is_static: is_static
receiver: receiver
name: name
language: language
typ: typ
stmts: stmts
pos: pos
is_public: is_public
is_method: is_method
is_static: is_static
receiver: receiver
name: name
language: language
typ: typ
stmts: stmts
pos: pos
}
}
@ -1832,10 +1832,10 @@ fn (mut p Parser) fn_parameters() []ast.Parameter {
typ = p.expect_type()
}
params << ast.Parameter{
name: name
typ: typ
name: name
typ: typ
is_mut: is_mut
pos: pos
pos: pos
}
if p.tok == .comma {
p.next()
@ -1860,7 +1860,7 @@ fn (mut p Parser) fn_arguments() []ast.Expr {
// `...varg`
.ellipsis {
ast.Expr(ast.PrefixExpr{
op: p.tok()
op: p.tok()
expr: p.expr(.lowest)
})
}
@ -1898,7 +1898,7 @@ fn (mut p Parser) fn_arguments() []ast.Expr {
p.error('expecting ident for struct config syntax?')
}
args << ast.FieldInit{
name: (expr as ast.Ident).name
name: (expr as ast.Ident).name
value: p.expr(.lowest)
}
if p.tok == .semicolon {
@ -1946,8 +1946,8 @@ fn (mut p Parser) enum_decl(is_public bool, attributes []ast.Attribute) ast.Enum
p.next()
}
fields << ast.FieldDecl{
name: field_name
value: value
name: field_name
value: value
attributes: field_attributes
}
}
@ -1956,10 +1956,10 @@ fn (mut p Parser) enum_decl(is_public bool, attributes []ast.Attribute) ast.Enum
p.expect(.semicolon)
return ast.EnumDecl{
attributes: attributes
is_public: is_public
name: name
as_type: as_type
fields: fields
is_public: is_public
name: name
as_type: as_type
fields: fields
}
}
@ -1980,13 +1980,13 @@ fn (mut p Parser) global_decl(attributes []ast.Attribute) ast.GlobalDecl {
if p.tok == .assign {
p.next()
fields << ast.FieldDecl{
name: name
name: name
value: p.expr(.lowest)
}
} else {
fields << ast.FieldDecl{
name: name
typ: p.expect_type()
typ: p.expect_type()
}
}
p.expect(.semicolon)
@ -2000,7 +2000,7 @@ fn (mut p Parser) global_decl(attributes []ast.Attribute) ast.GlobalDecl {
}
return ast.GlobalDecl{
attributes: attributes
fields: fields
fields: fields
}
}
@ -2032,7 +2032,7 @@ fn (mut p Parser) interface_decl(is_public bool, attributes []ast.Attribute) ast
}
fields << ast.FieldDecl{
name: field_name
typ: if p.tok == .lpar { ast.Type(p.fn_type()) } else { p.expect_type() }
typ: if p.tok == .lpar { ast.Type(p.fn_type()) } else { p.expect_type() }
}
}
// embedded interface
@ -2046,12 +2046,12 @@ fn (mut p Parser) interface_decl(is_public bool, attributes []ast.Attribute) ast
p.next()
p.expect(.semicolon)
return ast.InterfaceDecl{
is_public: is_public
attributes: attributes
name: name
is_public: is_public
attributes: attributes
name: name
generic_params: generic_params
embedded: embedded
fields: fields
embedded: embedded
fields: fields
}
}
@ -2070,23 +2070,23 @@ fn (mut p Parser) struct_decl(is_public bool, attributes []ast.Attribute) ast.St
p.error('v struct decl must have a body')
}
return ast.StructDecl{
is_public: is_public
language: language
name: name
is_public: is_public
language: language
name: name
generic_params: generic_params
pos: pos
pos: pos
}
}
embedded, fields := p.struct_decl_fields(language)
return ast.StructDecl{
attributes: attributes
is_public: is_public
embedded: embedded
language: language
name: name
attributes: attributes
is_public: is_public
embedded: embedded
language: language
name: name
generic_params: generic_params
fields: fields
pos: pos
fields: fields
pos: pos
}
}
@ -2141,9 +2141,9 @@ fn (mut p Parser) struct_decl_fields(language ast.Language) ([]ast.Expr, []ast.F
p.next()
}
fields << ast.FieldDecl{
name: field_name
typ: field_type
value: field_value
name: field_name
typ: field_type
value: field_value
attributes: field_attributes
}
}
@ -2163,10 +2163,10 @@ fn (mut p Parser) select_expr() ast.SelectExpr {
p.expect_semi()
}
select_expr := ast.SelectExpr{
pos: p.pos
stmt: stmt
pos: p.pos
stmt: stmt
stmts: stmts
next: if p.tok != .rcbr { p.select_expr() } else { ast.empty_expr }
next: if p.tok != .rcbr { p.select_expr() } else { ast.empty_expr }
}
return select_expr
}
@ -2186,15 +2186,15 @@ fn (mut p Parser) assoc_or_init_expr(typ ast.Expr) ast.Expr {
field_name := p.expect_name()
p.expect(.colon)
fields << ast.FieldInit{
name: field_name
name: field_name
value: p.expr(.lowest)
}
p.expect_semi()
}
p.next()
return ast.AssocExpr{
typ: typ
expr: lx
typ: typ
expr: lx
fields: fields
}
}
@ -2225,7 +2225,7 @@ fn (mut p Parser) assoc_or_init_expr(typ ast.Expr) ast.Expr {
p.next()
}
fields << ast.FieldInit{
name: field_name
name: field_name
value: value
}
if p.tok == .semicolon {
@ -2235,7 +2235,7 @@ fn (mut p Parser) assoc_or_init_expr(typ ast.Expr) ast.Expr {
}
p.next()
return ast.InitExpr{
typ: typ
typ: typ
fields: fields
}
}
@ -2244,7 +2244,7 @@ fn (mut p Parser) string_literal(kind ast.StringLiteralKind) ast.Expr {
value0 := p.lit()
if p.tok != .str_dollar {
return ast.StringLiteral{
kind: kind
kind: kind
value: value0
}
}
@ -2266,7 +2266,7 @@ fn (mut p Parser) string_literal(kind ast.StringLiteralKind) ast.Expr {
}
}
return ast.StringInterLiteral{
kind: kind
kind: kind
values: values
inters: inters
}
@ -2300,9 +2300,9 @@ fn (mut p Parser) string_inter() ast.StringInter {
}
}
return ast.StringInter{
format: format
format: format
format_expr: format_expr
expr: expr
expr: expr
}
}
@ -2347,11 +2347,11 @@ fn (mut p Parser) type_decl(is_public bool) ast.TypeDecl {
if p.tok != .pipe {
p.expect(.semicolon)
return ast.TypeDecl{
is_public: is_public
language: language
name: name
is_public: is_public
language: language
name: name
generic_params: generic_params
base_type: typ
base_type: typ
}
}
// sum type `type MyType = int | string`
@ -2364,18 +2364,18 @@ fn (mut p Parser) type_decl(is_public bool) ast.TypeDecl {
p.expect(.semicolon)
// TODO: consider separate node for alias / sum type ?
return ast.TypeDecl{
is_public: is_public
language: language
name: name
is_public: is_public
language: language
name: name
generic_params: generic_params
variants: variants
variants: variants
}
}
@[inline]
fn (mut p Parser) ident() ast.Ident {
return ast.Ident{
pos: p.pos
pos: p.pos
name: p.expect_name()
}
}
@ -2419,9 +2419,9 @@ fn (mut p Parser) current_position() token.Position {
pos := p.pos - p.file.base
return token.Position{
filename: p.file.name
line: p.line
offset: pos
column: pos - p.file.line_start(p.line) + 1
line: p.line
offset: pos
column: pos - p.file.line_start(p.line) + 1
}
}

View file

@ -25,7 +25,7 @@ fn (mut p Parser) try_type() ast.Expr {
.amp {
p.next()
return ast.PrefixExpr{
op: .amp
op: .amp
expr: p.expect_type()
}
}
@ -41,7 +41,7 @@ fn (mut p Parser) try_type() ast.Expr {
else {
// TODO: match only allowed tokens otherwise error
ast.Ident{
pos: p.pos
pos: p.pos
name: p.tok().str()
}
}
@ -53,7 +53,7 @@ fn (mut p Parser) try_type() ast.Expr {
p.next()
// TODO: what will we use here?
return ast.PrefixExpr{
op: .ellipsis
op: .ellipsis
expr: p.expect_type()
}
}
@ -91,8 +91,8 @@ fn (mut p Parser) try_type() ast.Expr {
// even though it technically is not one? hrmm
return ast.Type(ast.AnonStructType{
generic_params: generic_params
embedded: embedded
fields: fields
embedded: embedded
fields: fields
})
}
// tuple (multi return): `(type, type)`
@ -126,7 +126,7 @@ fn (mut p Parser) try_type() ast.Expr {
len_expr := p.expr(.lowest)
p.expect(.rsbr)
return ast.Type(ast.ArrayFixedType{
len: len_expr
len: len_expr
elem_type: p.expect_type()
})
}
@ -146,7 +146,7 @@ fn (mut p Parser) try_type() ast.Expr {
// perhaps we should rename it to ast.GenericTypes
// if name is ast.Ident && p.pos == pos + name.name.len { return name }
return ast.Type(ast.GenericType{
name: name
name: name
params: p.generic_list()
})
}
@ -181,8 +181,8 @@ fn (mut p Parser) fn_type() ast.FnType {
params := p.fn_parameters()
return ast.FnType{
generic_params: generic_params
params: params
return_type: if p.tok != .semicolon { p.try_type() } else { ast.empty_expr }
params: params
return_type: if p.tok != .semicolon { p.try_type() } else { ast.empty_expr }
}
}
@ -198,14 +198,14 @@ fn (mut p Parser) ident_or_named_type() ast.Expr {
key_type := p.expect_type()
p.expect(.rsbr)
return ast.Type(ast.MapType{
key_type: key_type
key_type: key_type
value_type: p.expect_type()
})
}
// struct called `map` in builtin
return ast.Ident{
name: 'map'
pos: pos
pos: pos
}
}
// `chan` | `chan type`
@ -220,7 +220,7 @@ fn (mut p Parser) ident_or_named_type() ast.Expr {
// struct called `chan` in builtin
return ast.Ident{
name: 'chan'
pos: pos
pos: pos
}
}
// `thread` | `thread type`
@ -240,7 +240,7 @@ fn (mut p Parser) ident_or_type() ast.Expr {
ident_or_selector := p.ident_or_selector_expr()
if p.tok == .lsbr {
return ast.Type(ast.GenericType{
name: ident_or_selector
name: ident_or_selector
params: p.generic_list()
})
}

View file

@ -25,11 +25,11 @@ pub fn new_preferences() Preferences {
pub fn new_preferences_using_options(options []string) Preferences {
return Preferences{
// config flags
debug: '--debug' in options || '-d' in options
verbose: '--verbose' in options || '-v' in options
skip_genv: '--skip-genv' in options
debug: '--debug' in options || '-d' in options
verbose: '--verbose' in options || '-v' in options
skip_genv: '--skip-genv' in options
skip_builtin: '--skip-builtin' in options
skip_imports: '--skip-imports' in options
no_parallel: '--no-parallel' in options
no_parallel: '--no-parallel' in options
}
}

View file

@ -35,8 +35,8 @@ pub mut:
pub fn new_scanner(prefs &pref.Preferences, mode Mode) &Scanner {
unsafe {
return &Scanner{
pref: prefs
mode: mode
pref: prefs
mode: mode
skip_interpolation: mode.has(.skip_interpolation)
}
}

View file

@ -174,9 +174,9 @@ pub fn (f &File) position(pos Pos) Position {
line, column := f.find_line_and_column(offset)
return Position{
filename: f.name
offset: offset
line: line
column: column
offset: offset
line: line
column: column
}
}

View file

@ -60,9 +60,9 @@ mut:
pub fn Checker.new(prefs &pref.Preferences, file_set &token.FileSet, env &Environment) &Checker {
return &Checker{
pref: unsafe { prefs }
pref: unsafe { prefs }
file_set: unsafe { file_set }
env: unsafe { env }
env: unsafe { env }
}
}
@ -235,7 +235,7 @@ fn (mut c Checker) decl(decl ast.Stmt) {
for field in decl.fields {
// c.log('const decl: $field.name')
obj := Const{
mod: c.mod
mod: c.mod
name: field.name
// typ: c.expr(field.value)
}
@ -266,8 +266,8 @@ fn (mut c Checker) decl(decl ast.Stmt) {
// as_type := decl.as_type !is ast.EmptyExpr { c.expr(decl.as_type) } else { Type(int_) }
obj := Enum{
is_flag: decl.attributes.has('flag')
name: decl.name
fields: fields
name: decl.name
fields: fields
}
c.scope.insert(obj.name, Type(obj))
}
@ -311,7 +311,7 @@ fn (mut c Checker) decl(decl ast.Stmt) {
for field in interface_decl.fields {
fields << Field{
name: field.name
typ: c.expr(field.typ)
typ: c.expr(field.typ)
}
}
if mut id := scope.lookup(interface_decl.name) {
@ -333,7 +333,7 @@ fn (mut c Checker) decl(decl ast.Stmt) {
for field in struct_decl.fields {
fields << Field{
name: field.name
typ: c.expr(field.typ)
typ: c.expr(field.typ)
}
}
mut embedded := []Struct{}
@ -501,7 +501,7 @@ fn (mut c Checker) expr(expr ast.Expr) Type {
c.expected_type = expected_type_prev
return if is_fixed {
ArrayFixed{
len: expr.exprs.len
len: expr.exprs.len
elem_type: first_elem_type
}
} else {
@ -616,7 +616,7 @@ fn (mut c Checker) expr(expr ast.Expr) Type {
}
return Struct{
name: name
name: name
generic_params: args
}
}
@ -739,7 +739,7 @@ fn (mut c Checker) expr(expr ast.Expr) Type {
key0_type := c.expr(expr.keys[0])
value0_type := c.expr(expr.vals[0])
return Map{
key_type: key0_type
key_type: key0_type
value_type: value0_type
}
}
@ -890,7 +890,7 @@ fn (mut c Checker) expr(expr ast.Expr) Type {
}
ast.MapType {
return Map{
key_type: c.expr(expr.key_type)
key_type: c.expr(expr.key_type)
value_type: c.expr(expr.value_type)
}
}
@ -980,7 +980,7 @@ fn (mut c Checker) stmt(stmt ast.Stmt) {
}
obj := Global{
name: field.name
typ: field_type
typ: field_type
}
c.scope.insert(field.name, obj)
}
@ -1057,8 +1057,8 @@ fn (mut c Checker) stmt_list(stmts []ast.Stmt) {
fn (mut c Checker) later(func fn (), kind DeferredKind) {
c.deferred << Deferred{
kind: kind
func: func
kind: kind
func: func
scope: c.scope
}
}
@ -1254,7 +1254,7 @@ fn (mut c Checker) fn_decl(decl ast.FnDecl) {
mut typ := Type(c.fn_type(decl.typ, FnTypeAttribute.from_ast_attributes(decl.attributes)))
obj := Fn{
name: decl.name
typ: typ
typ: typ
}
// TODO:
if decl.is_method {
@ -1473,13 +1473,13 @@ fn (mut c Checker) resolve_generic_arg_or_index_expr(expr ast.GenericArgOrIndexE
// expr_type := c.expr(expr.expr)
if lhs_type is FnType {
return ast.GenericArgs{
lhs: expr.lhs
lhs: expr.lhs
args: [expr.expr]
}
} else {
// c.unwrap_lhs_expr(ast.IndexExpr{lhs: expr.lhs, expr: expr.expr})
return ast.IndexExpr{
lhs: expr.lhs
lhs: expr.lhs
expr: expr.expr
}
}
@ -1490,16 +1490,16 @@ fn (mut c Checker) resolve_call_or_cast_expr(expr ast.CallOrCastExpr) ast.Expr {
// expr_type := c.expr(expr.expr)
if lhs_type is FnType {
return ast.CallExpr{
lhs: expr.lhs
lhs: expr.lhs
args: [expr.expr]
pos: expr.pos
pos: expr.pos
}
} else {
// c.log(expr)
return ast.CastExpr{
typ: expr.lhs
typ: expr.lhs
expr: expr.expr
pos: expr.pos
pos: expr.pos
}
}
}
@ -1693,7 +1693,7 @@ fn (mut c Checker) call_expr(expr ast.CallExpr) Type {
// c.log('#### ${expr.lhs.rhs.name}')
fn_ = FnType{
return_type: Type(Alias{
name: 'Duration'
name: 'Duration'
base_type: i64_
})
}
@ -1872,7 +1872,7 @@ fn (mut c Checker) fn_type(fn_type ast.FnType, attributes FnTypeAttribute) FnTyp
params << Parameter{
name: param.name
// typ: c.expr(param.typ)
typ: param_type
typ: param_type
is_mut: param.is_mut
}
c.scope.insert(param.name, param_type)
@ -1888,11 +1888,11 @@ fn (mut c Checker) fn_type(fn_type ast.FnType, attributes FnTypeAttribute) FnTyp
mut typ := FnType{
generic_params: generic_params
params: params
params: params
// return_type: return_type
return_type: c.expr(fn_type.return_type)
is_variadic: is_variadic
attributes: attributes
attributes: attributes
// scope: c.scope
}
if generic_params.len > 0 {

View file

@ -12,8 +12,8 @@ pub struct Module {
pub fn new_module(name string, path string) &Module {
return &Module{
name: name
path: path
name: name
path: path
scope: new_scope(universe)
}
}

View file

@ -289,7 +289,7 @@ fn (t Type) typed_default() Type {
return Primitive{
...t
props: concrete_props
size: size
size: size
}
}
return t

View file

@ -13,15 +13,15 @@ const bool_ = Primitive{
}
const i8_ = Primitive{
props: .integer
size: 8
size: 8
}
const i16_ = Primitive{
props: .integer
size: 16
size: 16
}
const i32_ = Primitive{
props: .integer
size: 32
size: 32
}
// TODO: represent platform specific size
// will this be calculated at compile time?
@ -31,36 +31,36 @@ const int_ = Primitive{
}
const i64_ = Primitive{
props: .integer
size: 64
size: 64
}
const u8_ = Primitive{
props: .integer | .unsigned
size: 8
size: 8
}
// byte_ = Primitive{props: .integer | .unsigned, size: 8}
const byte_ = Alias{
name: 'byte'
name: 'byte'
base_type: u8_
}
const u16_ = Primitive{
props: .integer | .unsigned
size: 16
size: 16
}
const u32_ = Primitive{
props: .integer | .unsigned
size: 32
size: 32
}
const u64_ = Primitive{
props: .integer | .unsigned
size: 64
size: 64
}
const f32_ = Primitive{
props: .float
size: 32
size: 32
}
const f64_ = Primitive{
props: .float
size: 64
size: 64
}
// complex / non primitives
const string_ = String(0)
@ -73,19 +73,19 @@ const void_ = Void(0)
const nil_ = Nil(0)
const none_ = None(0)
const byteptr_ = Alias{
name: 'byteptr'
name: 'byteptr'
base_type: Pointer{
base_type: byte_
}
}
const charptr_ = Alias{
name: 'charptr'
name: 'charptr'
base_type: Pointer{
base_type: char_
}
}
const voidptr_ = Alias{
name: 'voidptr'
name: 'voidptr'
base_type: Pointer{
base_type: void_
}

View file

@ -16,7 +16,7 @@ mut:
pub fn WorkerPool.new[T, Y]() &WorkerPool[T, Y] {
return &WorkerPool[T, Y]{
ch_in: chan T{cap: 1000}
ch_in: chan T{cap: 1000}
ch_out: chan Y{cap: 1000}
}
}