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

ast: minor cleanup of ast.v (#8859)

This commit is contained in:
yuyi 2021-02-21 02:50:43 +08:00 committed by GitHub
parent c190b6a131
commit 8f486cb8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1226,14 +1226,11 @@ pub fn (expr Expr) position() token.Position {
AnonFn { AnonFn {
return expr.decl.pos return expr.decl.pos
} }
ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit, CharLiteral, ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, ChanInit,
ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr, IntegerLiteral, CharLiteral, ConcatExpr, Comment, EnumVal, FloatLiteral, GoExpr, Ident, IfExpr, IndexExpr,
Likely, LockExpr, MapInit, MatchExpr, None, OffsetOf, OrExpr, ParExpr, PostfixExpr, PrefixExpr, IntegerLiteral, Likely, LockExpr, MapInit, MatchExpr, None, OffsetOf, OrExpr, ParExpr,
RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral, StringLiteral, PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr, StringInterLiteral,
StructInit, Type, TypeOf, UnsafeExpr { StringLiteral, StructInit, Type, TypeOf, UnsafeExpr {
return expr.pos
}
ArrayDecompose {
return expr.pos return expr.pos
} }
IfGuardExpr { IfGuardExpr {
@ -1290,6 +1287,25 @@ pub fn (expr Expr) is_lit() bool {
} }
} }
pub fn (expr Expr) is_mut_ident() bool {
match expr {
Ident {
if expr.obj is Var {
if expr.obj.is_auto_deref {
return true
}
}
}
PrefixExpr {
if expr.op == .amp && expr.right.is_mut_ident() {
return true
}
}
else {}
}
return false
}
// check if stmt can be an expression in C // check if stmt can be an expression in C
pub fn (stmt Stmt) check_c_expr() ? { pub fn (stmt Stmt) check_c_expr() ? {
match stmt { match stmt {
@ -1536,25 +1552,6 @@ pub struct Table {
// main_fn_decl_node FnDecl // main_fn_decl_node FnDecl
} }
pub fn (expr Expr) is_mut_ident() bool {
match expr {
Ident {
if expr.obj is Var {
if expr.obj.is_auto_deref {
return true
}
}
}
PrefixExpr {
if expr.op == .amp && expr.right.is_mut_ident() {
return true
}
}
else {}
}
return false
}
// helper for dealing with `m[k1][k2][k3][k3] = value` // helper for dealing with `m[k1][k2][k3][k3] = value`
pub fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool) { pub fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool) {
lx.is_setter = val lx.is_setter = val