From 79b26b16545340c030b8a4bf1dc28bd0be95bcc4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 5 Dec 2019 19:02:33 +0300 Subject: [PATCH] use get_type2 in struct.v --- vlib/compiler/get_type.v | 13 ++++++++++++- vlib/compiler/parser.v | 2 +- vlib/compiler/struct.v | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vlib/compiler/get_type.v b/vlib/compiler/get_type.v index 877979d00d..0f77072d1d 100644 --- a/vlib/compiler/get_type.v +++ b/vlib/compiler/get_type.v @@ -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('__') { diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 2bdb6b3564..4767d1879c 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -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, diff --git a/vlib/compiler/struct.v b/vlib/compiler/struct.v index 213eeb2be1..15d0524cd7 100644 --- a/vlib/compiler/struct.v +++ b/vlib/compiler/struct.v @@ -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_') {