mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: lots of small fixes parent method/field resolution
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// that can be found in the LICENSE file.
|
||||
module table
|
||||
|
||||
pub type TypeInfo = Array | ArrayFixed | Map | Struct | MultiReturn | Variadic
|
||||
pub type TypeInfo = Array | ArrayFixed | Map | Struct | MultiReturn
|
||||
|
||||
pub struct Type {
|
||||
pub:
|
||||
@@ -47,6 +47,13 @@ pub const (
|
||||
// map_type_idx = 18
|
||||
)
|
||||
|
||||
pub const (
|
||||
builtin_type_names = [
|
||||
'void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64',
|
||||
'f32' ,'f64', 'string', 'char', 'byte' ,'bool', 'struct', 'array', 'array_fixed', 'map'
|
||||
]
|
||||
)
|
||||
|
||||
pub enum Kind {
|
||||
placeholder
|
||||
void
|
||||
@@ -66,14 +73,13 @@ pub enum Kind {
|
||||
char
|
||||
byte
|
||||
bool
|
||||
const_
|
||||
enum_
|
||||
//const_
|
||||
//enum_
|
||||
struct_
|
||||
array
|
||||
array_fixed
|
||||
map
|
||||
multi_return
|
||||
variadic
|
||||
unresolved
|
||||
}
|
||||
|
||||
@@ -371,9 +377,6 @@ pub fn (k Kind) str() string {
|
||||
.multi_return{
|
||||
'multi_return'
|
||||
}
|
||||
.variadic{
|
||||
'variadic'
|
||||
}
|
||||
else {
|
||||
'unknown'}
|
||||
}
|
||||
@@ -407,6 +410,7 @@ pub mut:
|
||||
pub struct Field {
|
||||
pub:
|
||||
name string
|
||||
mut:
|
||||
typ TypeRef
|
||||
// type_idx int
|
||||
}
|
||||
@@ -447,11 +451,6 @@ mut:
|
||||
types []TypeRef
|
||||
}
|
||||
|
||||
pub struct Variadic {
|
||||
pub:
|
||||
typ TypeRef
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (t &Table) get_type(idx int) &Type {
|
||||
if idx == 0 {
|
||||
|
||||
@@ -27,6 +27,7 @@ pub:
|
||||
name string
|
||||
args []Var
|
||||
return_type TypeRef
|
||||
is_variadic bool
|
||||
is_c bool
|
||||
}
|
||||
|
||||
@@ -279,6 +280,19 @@ pub fn (t &Table) find_type(name string) ?Type {
|
||||
return none
|
||||
}
|
||||
|
||||
// this will override or register builtin type
|
||||
// allows prexisitng types added in register_builtins
|
||||
// to be overriden with their real type info
|
||||
[inline]
|
||||
pub fn (t mut Table) register_builtin_type(typ Type) int {
|
||||
existing_idx := t.type_idxs[typ.name]
|
||||
if existing_idx > 0 {
|
||||
t.types[existing_idx] = typ
|
||||
return existing_idx
|
||||
}
|
||||
return t.register_type(typ)
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (t mut Table) register_type(typ Type) int {
|
||||
existing_idx := t.type_idxs[typ.name]
|
||||
@@ -399,25 +413,6 @@ pub fn (t mut Table) find_or_register_multi_return(mr_typs []TypeRef) int {
|
||||
return t.register_type(mr_type)
|
||||
}
|
||||
|
||||
pub fn (t mut Table) find_or_register_variadic(variadic_typ TypeRef) int {
|
||||
name := 'variadic_$variadic_typ.typ.name'
|
||||
// existing
|
||||
existing_idx := t.type_idxs[name]
|
||||
if existing_idx > 0 {
|
||||
return existing_idx
|
||||
}
|
||||
// register
|
||||
variadic_type := Type{
|
||||
parent: 0
|
||||
kind: .variadic
|
||||
name: name
|
||||
info: Variadic{
|
||||
typ: variadic_typ
|
||||
}
|
||||
}
|
||||
return t.register_type(variadic_type)
|
||||
}
|
||||
|
||||
pub fn (t mut Table) add_placeholder_type(name string) int {
|
||||
ph_type := Type{
|
||||
parent: 0
|
||||
@@ -433,6 +428,9 @@ pub fn (t &Table) check(got, expected &TypeRef) bool {
|
||||
if expected.typ.kind == .voidptr {
|
||||
return true
|
||||
}
|
||||
if expected.typ.kind in [.voidptr, .byteptr, .charptr] && got.typ.kind == .int {
|
||||
return true
|
||||
}
|
||||
if expected.typ.kind == .byteptr && got.typ.kind == .voidptr {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user