mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: simplify type sizeof check and fix c2v globals
This commit is contained in:
parent
697eca5ddf
commit
0e1cfd4a28
@ -15,10 +15,13 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||
if expected == ast.byteptr_type {
|
||||
return true
|
||||
}
|
||||
if expected == ast.voidptr_type {
|
||||
return true
|
||||
}
|
||||
if expected.is_any_kind_of_pointer() { //&& !got.is_any_kind_of_pointer() {
|
||||
// Allow `int` as `&i8` etc in C code.
|
||||
// deref := expected.deref()
|
||||
deref := expected.set_nr_muls(0)
|
||||
deref := expected.deref()
|
||||
// deref := expected.set_nr_muls(0)
|
||||
got_sym := c.table.sym(got)
|
||||
if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum_) {
|
||||
return true
|
||||
|
@ -197,8 +197,11 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
||||
pos := p.tok.position()
|
||||
is_known_var := p.mark_var_as_used(p.tok.lit)
|
||||
|| p.table.global_scope.known_const(p.mod + '.' + p.tok.lit)
|
||||
//|| p.table.known_fn(p.mod + '.' + p.tok.lit)
|
||||
// assume `mod.` prefix leads to a type
|
||||
if is_known_var || !(p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type()) {
|
||||
is_type := p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type()
|
||||
|| (p.tok.lit.len > 0 && p.tok.lit[0].is_capital())
|
||||
if is_known_var || !is_type {
|
||||
expr := p.expr(0)
|
||||
if is_reftype {
|
||||
node = ast.IsRefType{
|
||||
|
@ -3596,6 +3596,7 @@ fn (mut p Parser) rewind_scanner_to_current_token_in_new_mode() {
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if `varname` is known
|
||||
pub fn (mut p Parser) mark_var_as_used(varname string) bool {
|
||||
if obj := p.scope.find(varname) {
|
||||
match mut obj {
|
||||
@ -3603,6 +3604,10 @@ pub fn (mut p Parser) mark_var_as_used(varname string) bool {
|
||||
obj.is_used = true
|
||||
return true
|
||||
}
|
||||
ast.GlobalField {
|
||||
// obj.is_used = true
|
||||
return true
|
||||
}
|
||||
// ast.ConstField {
|
||||
// return true
|
||||
//}
|
||||
|
Loading…
Reference in New Issue
Block a user