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

use get_type2 in struct.v

This commit is contained in:
Alexander Medvednikov 2019-12-05 19:02:33 +03:00
parent cca650c655
commit 79b26b1654
3 changed files with 16 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import (
strings
)
fn (p mut Parser) get_type3() Type{
fn (p mut Parser) get_type2() Type{
mut mul := false
mut nr_muls := 0
mut typ := ''
@ -189,6 +189,17 @@ fn (p mut Parser) get_type3() Type{
typ = 'Option_$typ'
p.table.register_type_with_parent(typ, 'Option')
}
// Because the code uses * to see if it's a pointer
if typ == 'byteptr' {
typ = 'byte*'
}
if typ == 'voidptr' {
//if !p.builtin_mod && p.mod != 'os' && p.mod != 'gx' && p.mod != 'gg' && !p.pref.translated {
//p.error('voidptr can only be used in unsafe code')
//}
typ = 'void*'
}
/*
TODO this is not needed?
if typ.last_index('__') > typ.index('__') {

View File

@ -740,7 +740,7 @@ fn (p mut Parser) type_decl() {
if p.tok == .key_struct {
p.error('use `struct $name {` instead of `type $name struct {`')
}
parent := p.get_type3()
parent := p.get_type2()
nt_pair := p.table.cgen_name_type_pair(name, parent.name)
// TODO dirty C typedef hacks for DOOM
// Unknown type probably means it's a struct, and it's used before the struct is defined,

View File

@ -194,9 +194,10 @@ fn (p mut Parser) struct_decl() {
// `pub` access mod
access_mod := if is_pub_field { AccessMod.public } else { AccessMod.private}
p.fspace()
field_type := p.get_type()
tt := p.get_type2()
field_type := tt.name
if field_type == name {
p.error_with_token_index( 'cannot embed struct `$name` in itself (field `$field_name`)', field_name_token_idx)
p.error_with_token_index('cannot embed struct `$name` in itself (field `$field_name`)', field_name_token_idx)
}
// Register ?option type
if field_type.starts_with('Option_') {