1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: minor cleanup in ast.v (#17962)

This commit is contained in:
yuyi 2023-04-15 19:29:15 +08:00 committed by GitHub
parent 7c9f273e33
commit a938dcddb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,11 +165,11 @@ pub:
pos token.Pos pos token.Pos
} }
pub const empty_expr = Expr(EmptyExpr(0)) pub const (
empty_expr = Expr(EmptyExpr(0))
pub const empty_stmt = Stmt(EmptyStmt{}) empty_stmt = Stmt(EmptyStmt{})
empty_node = Node(EmptyNode{})
pub const empty_node = Node(EmptyNode{}) )
// `{stmts}` or `unsafe {stmts}` // `{stmts}` or `unsafe {stmts}`
pub struct Block { pub struct Block {
@ -560,11 +560,11 @@ pub mut:
should_be_skipped bool // true, when -skip-unused could not find any usages of that function, starting from main + other known used functions should_be_skipped bool // true, when -skip-unused could not find any usages of that function, starting from main + other known used functions
ninstances int // 0 for generic functions with no concrete instances ninstances int // 0 for generic functions with no concrete instances
has_await bool // 'true' if this function uses JS.await has_await bool // 'true' if this function uses JS.await
//
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment` end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment`
next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl
//
source_file &File = unsafe { nil } source_file &File = unsafe { nil }
scope &Scope = unsafe { nil } scope &Scope = unsafe { nil }
label_names []string label_names []string
@ -725,6 +725,7 @@ pub struct AutofreeArgVar {
idx int idx int
} }
*/ */
// function call argument: `f(callarg)` // function call argument: `f(callarg)`
[minify] [minify]
pub struct CallArg { pub struct CallArg {
@ -963,7 +964,6 @@ pub fn (i &Ident) var_info() IdentVar {
return i.info return i.info
} }
else { else {
// return IdentVar{}
panic('Ident.var_info(): info is not IdentVar variant') panic('Ident.var_info(): info is not IdentVar variant')
} }
} }
@ -985,12 +985,12 @@ pub mut:
promoted_type Type = void_type promoted_type Type = void_type
auto_locked string auto_locked string
or_block OrExpr or_block OrExpr
//
ct_left_value_evaled bool ct_left_value_evaled bool
ct_left_value ComptTimeConstValue = empty_comptime_const_expr() ct_left_value ComptTimeConstValue = empty_comptime_const_expr()
ct_right_value_evaled bool ct_right_value_evaled bool
ct_right_value ComptTimeConstValue = empty_comptime_const_expr() ct_right_value ComptTimeConstValue = empty_comptime_const_expr()
//
before_op_comments []Comment before_op_comments []Comment
after_op_comments []Comment after_op_comments []Comment
} }
@ -1153,7 +1153,6 @@ pub:
pos token.Pos pos token.Pos
typ_pos token.Pos typ_pos token.Pos
pub mut: pub mut:
// expr Expr
typ Type typ Type
} }
@ -1232,6 +1231,7 @@ pub:
name string name string
} }
*/ */
// variable assign statement // variable assign statement
[minify] [minify]
pub struct AssignStmt { pub struct AssignStmt {
@ -1816,21 +1816,17 @@ pub mut:
[minify] [minify]
pub struct ComptimeCall { pub struct ComptimeCall {
pub: pub:
pos token.Pos pos token.Pos
has_parens bool // if $() is used, for vfmt has_parens bool // if $() is used, for vfmt
method_name string method_name string
method_pos token.Pos method_pos token.Pos
scope &Scope = unsafe { nil } scope &Scope = unsafe { nil }
left Expr left Expr
// is_vweb bool
is_vweb bool vweb_tmpl File
vweb_tmpl File is_embed bool
// is_env bool
is_embed bool env_pos token.Pos
//
is_env bool
env_pos token.Pos
//
is_pkgconfig bool is_pkgconfig bool
pub mut: pub mut:
left_type Type left_type Type
@ -1967,28 +1963,22 @@ pub fn (expr Expr) pos() token.Pos {
} }
pub fn (expr Expr) is_lvalue() bool { pub fn (expr Expr) is_lvalue() bool {
match expr { return match expr {
Ident { return true } Ident, CTempVar { true }
CTempVar { return true } IndexExpr { expr.left.is_lvalue() }
IndexExpr { return expr.left.is_lvalue() } SelectorExpr { expr.expr.is_lvalue() }
SelectorExpr { return expr.expr.is_lvalue() } ParExpr { expr.expr.is_lvalue() } // for var := &{...(*pointer_var)}
ParExpr { return expr.expr.is_lvalue() } // for var := &{...(*pointer_var)} PrefixExpr { expr.right.is_lvalue() }
PrefixExpr { return expr.right.is_lvalue() } ComptimeSelector { expr.field_expr.is_lvalue() }
ComptimeSelector { return expr.field_expr.is_lvalue() } else { false }
else {}
} }
return false
} }
pub fn (expr Expr) is_expr() bool { pub fn (expr Expr) is_expr() bool {
match expr { return match expr {
IfExpr { return expr.is_expr } IfExpr, LockExpr, MatchExpr, SelectExpr { expr.is_expr }
LockExpr { return expr.is_expr } else { true }
MatchExpr { return expr.is_expr }
SelectExpr { return expr.is_expr }
else {}
} }
return true
} }
pub fn (expr Expr) is_pure_literal() bool { pub fn (expr Expr) is_pure_literal() bool {
@ -2019,16 +2009,10 @@ pub fn (expr Expr) is_auto_deref_var() bool {
// returns if an expression can be used in `lock x, y.z {` // returns if an expression can be used in `lock x, y.z {`
pub fn (e &Expr) is_lockable() bool { pub fn (e &Expr) is_lockable() bool {
match e { return match e {
Ident { Ident { true }
return true SelectorExpr { e.expr.is_lockable() }
} else { false }
SelectorExpr {
return e.expr.is_lockable()
}
else {
return false
}
} }
} }