mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: match expr fixes & tmp typeof skip
This commit is contained in:
parent
a8f07157dd
commit
f57a651e3b
@ -12,7 +12,7 @@ pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLitera
|
||||
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
||||
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
||||
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | IfGuardExpr | ParExpr | OrExpr |
|
||||
ConcatExpr
|
||||
ConcatExpr | TypeName
|
||||
|
||||
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
||||
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
||||
@ -27,6 +27,12 @@ pub struct StructType {
|
||||
|
||||
pub struct ArrayType {}
|
||||
|
||||
pub struct TypeName {
|
||||
pub:
|
||||
name string
|
||||
typ table.Type
|
||||
}
|
||||
|
||||
// | IncDecStmt k
|
||||
// Stand-alone expression in a statement list.
|
||||
pub struct ExprStmt {
|
||||
|
@ -175,6 +175,10 @@ fn (c mut Checker) check_assign_expr(assign_expr ast.AssignExpr) {
|
||||
|
||||
pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type {
|
||||
fn_name := call_expr.name
|
||||
// TODO: impl typeof properly (probably not going to be a fn call)
|
||||
if fn_name == 'typeof' {
|
||||
return table.string_type
|
||||
}
|
||||
mut found := false
|
||||
// start hack: until v1 is fixed and c definitions are added for these
|
||||
if fn_name == 'C.calloc' {
|
||||
@ -553,6 +557,9 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
||||
ast.StructInit {
|
||||
return c.check_struct_init(it)
|
||||
}
|
||||
ast.TypeName {
|
||||
return it.typ
|
||||
}
|
||||
/*
|
||||
ast.UnaryExpr {
|
||||
c.expr(it.left)
|
||||
@ -656,7 +663,12 @@ pub fn (c mut Checker) match_expr(node mut ast.MatchExpr) table.Type {
|
||||
if i < node.match_exprs.len {
|
||||
match_expr := node.match_exprs[i]
|
||||
c.expected_type = t
|
||||
c.expr(match_expr)
|
||||
typ := c.expr(match_expr)
|
||||
typ_sym := c.table.get_type_symbol(typ)
|
||||
// TODO:
|
||||
if typ_sym.kind == .sum_type {
|
||||
|
||||
}
|
||||
}
|
||||
c.stmts(block.stmts)
|
||||
// If the last statement is an expression, return its type
|
||||
|
@ -1732,16 +1732,21 @@ fn (p mut Parser) match_expr() ast.Expr {
|
||||
mut match_exprs := []ast.Expr
|
||||
// mut return_type := table.void_type
|
||||
for {
|
||||
p.open_scope()
|
||||
// Sum type match
|
||||
if p.tok.kind == .name && (p.tok.lit[0].is_capital() || p.peek_tok.kind == .dot) {
|
||||
// if sym.kind == .sum_type {
|
||||
// p.warn('is sum')
|
||||
// p.parse_type()
|
||||
p.check_name()
|
||||
if p.tok.kind == .dot {
|
||||
p.check(.dot)
|
||||
p.check_name()
|
||||
typ := p.parse_type()
|
||||
typ_sym := p.table.get_type_symbol(typ)
|
||||
match_exprs << ast.TypeName{
|
||||
name: typ_sym.name
|
||||
typ: typ
|
||||
}
|
||||
p.scope.register_var(ast.VarDecl{
|
||||
name: 'it'
|
||||
typ: typ
|
||||
})
|
||||
}
|
||||
else {
|
||||
// Expression match
|
||||
@ -1778,7 +1783,7 @@ fn (p mut Parser) match_expr() ast.Expr {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
p.close_scope()
|
||||
if p.tok.kind == .rcbr {
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user