checker: check ! operator
parent
718819eb7a
commit
831be43740
|
@ -319,18 +319,6 @@ mut:
|
||||||
right_type table.Type
|
right_type table.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// renamed to PrefixExpr
|
|
||||||
pub struct UnaryExpr {
|
|
||||||
pub:
|
|
||||||
// tok_kind token.Kind
|
|
||||||
// op BinaryOp
|
|
||||||
op token.Kind
|
|
||||||
left Expr
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
pub struct PostfixExpr {
|
pub struct PostfixExpr {
|
||||||
pub:
|
pub:
|
||||||
op token.Kind
|
op token.Kind
|
||||||
|
@ -342,6 +330,7 @@ pub struct PrefixExpr {
|
||||||
pub:
|
pub:
|
||||||
op token.Kind
|
op token.Kind
|
||||||
right Expr
|
right Expr
|
||||||
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IndexExpr {
|
pub struct IndexExpr {
|
||||||
|
@ -528,9 +517,9 @@ pub struct DeferStmt {
|
||||||
pub:
|
pub:
|
||||||
stmts []Stmt
|
stmts []Stmt
|
||||||
mut:
|
mut:
|
||||||
// TODO: handle this differently
|
// TODO: handle this differently
|
||||||
// v1 excludes non current os ifdefs so
|
// v1 excludes non current os ifdefs so
|
||||||
// the defer's never get added in the first place
|
// the defer's never get added in the first place
|
||||||
ifdef string
|
ifdef string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -746,6 +746,9 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
||||||
if it.op == .mul && table.type_is_ptr(right_type) {
|
if it.op == .mul && table.type_is_ptr(right_type) {
|
||||||
return table.type_deref(right_type)
|
return table.type_deref(right_type)
|
||||||
}
|
}
|
||||||
|
if it.op == .not && right_type != table.bool_type_idx {
|
||||||
|
c.error('! operator can only be used with bool types', it.pos)
|
||||||
|
}
|
||||||
return right_type
|
return right_type
|
||||||
}
|
}
|
||||||
ast.None {
|
ast.None {
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||||
pref: &pref.Preferences{}
|
pref: &pref.Preferences{}
|
||||||
scope: scope
|
scope: scope
|
||||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||||
|
|
||||||
}
|
}
|
||||||
p.init_parse_fns()
|
p.init_parse_fns()
|
||||||
p.read_first_token()
|
p.read_first_token()
|
||||||
|
@ -70,13 +70,14 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
|
||||||
scanner: scanner.new_scanner_file(path, comments_mode)
|
scanner: scanner.new_scanner_file(path, comments_mode)
|
||||||
table: table
|
table: table
|
||||||
file_name: path
|
file_name: path
|
||||||
pref: pref //&pref.Preferences{}
|
pref: pref // &pref.Preferences{}
|
||||||
|
|
||||||
scope: &ast.Scope{
|
scope: &ast.Scope{
|
||||||
start_pos: 0
|
start_pos: 0
|
||||||
parent: 0
|
parent: 0
|
||||||
}
|
}
|
||||||
// comments_mode: comments_mode
|
// comments_mode: comments_mode
|
||||||
|
|
||||||
}
|
}
|
||||||
p.read_first_token()
|
p.read_first_token()
|
||||||
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
||||||
|
@ -687,7 +688,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||||
p.expr_mod = ''
|
p.expr_mod = ''
|
||||||
return ast.EnumVal{
|
return ast.EnumVal{
|
||||||
enum_name: enum_name // lp.prepend_mod(enum_name)
|
enum_name: enum_name // lp.prepend_mod(enum_name)
|
||||||
|
|
||||||
val: val
|
val: val
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
mod: mod
|
mod: mod
|
||||||
|
@ -777,7 +778,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
||||||
node = ast.SizeOf{
|
node = ast.SizeOf{
|
||||||
typ: sizeof_type
|
typ: sizeof_type
|
||||||
// type_name: type_name
|
// type_name: type_name
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_typeof {
|
.key_typeof {
|
||||||
|
@ -904,6 +905,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
||||||
|
pos := p.tok.position()
|
||||||
op := p.tok.kind
|
op := p.tok.kind
|
||||||
if op == .amp {
|
if op == .amp {
|
||||||
p.is_amp = true
|
p.is_amp = true
|
||||||
|
@ -914,6 +916,7 @@ fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
||||||
return ast.PrefixExpr{
|
return ast.PrefixExpr{
|
||||||
op: op
|
op: op
|
||||||
right: right
|
right: right
|
||||||
|
pos: pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,7 +1048,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
|
||||||
left: left
|
left: left
|
||||||
right: right
|
right: right
|
||||||
// right_type: typ
|
// right_type: typ
|
||||||
|
|
||||||
op: op
|
op: op
|
||||||
pos: pos
|
pos: pos
|
||||||
}
|
}
|
||||||
|
@ -1450,7 +1453,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
|
||||||
fields << ast.Field{
|
fields << ast.Field{
|
||||||
name: name
|
name: name
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
}
|
}
|
||||||
exprs << expr
|
exprs << expr
|
||||||
// TODO: once consts are fixed reg here & update in checker
|
// TODO: once consts are fixed reg here & update in checker
|
||||||
|
|
Loading…
Reference in New Issue