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

parser: C enums + another enum simplification

This commit is contained in:
Alexander Medvednikov
2019-11-06 04:43:13 +03:00
parent 91bb969ed1
commit 855a736a2c
6 changed files with 31 additions and 26 deletions

View File

@ -4,20 +4,24 @@
module compiler
fn (p mut Parser) enum_decl(_enum_name string) {
mut enum_name := _enum_name
fn (p mut Parser) enum_decl(no_name bool) {
is_pub := p.tok == .key_pub
if is_pub {
p.next()
p.check(.key_enum)
enum_name = p.check_name()
}
p.check(.key_enum)
mut enum_name := p.check_name()
is_c := enum_name == 'C' && p.tok == .dot
if is_c {
p.check(.dot)
enum_name = p.check_name()
}
// Specify full type name
if !p.builtin_mod && p.mod != 'main' {
enum_name = p.prepend_mod(enum_name)
}
// Skip empty enums
if enum_name != 'int' && !p.first_pass() {
if !no_name && !p.first_pass() {
p.cgen.typedefs << 'typedef int $enum_name;'
}
p.check(.lcbr)
@ -55,7 +59,7 @@ fn (p mut Parser) enum_decl(_enum_name string) {
name: enum_name
mod: p.mod
parent: 'int'
cat: TypeCategory.enum_
cat: .enum_ //.enum_ //if is_c { TypeCategory.c_struct } else {TypeCategory.enum_ }
enum_vals: fields.clone()
is_public: is_pub
})