final vfmt run before CI check

This commit is contained in:
Alexander Medvednikov 2019-12-22 00:54:37 +03:00
parent 2b9392c46c
commit ef28a6b872
10 changed files with 92 additions and 86 deletions

View file

@ -7,6 +7,8 @@ import (
strings
)
// also unions and interfaces
fn (p mut Parser) struct_decl(generic_param_types []string) {
decl_tok_idx := p.cur_tok_index()
is_pub := p.tok == .key_pub
@ -39,26 +41,25 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
if is_interface && !name.ends_with('er') {
p.error('interface names temporarily have to end with `er` (e.g. `Speaker`, `Reader`)')
}
mut generic_types := map[string]string
mut is_generic := false
if p.tok == .lt {
p.check(.lt)
for i := 0; ; i++ {
if generic_param_types.len > 0 && i > generic_param_types.len-1 {
if generic_param_types.len > 0 && i > generic_param_types.len - 1 {
p.error('mismatched generic type params')
}
type_param := p.check_name()
generic_types[type_param] = if generic_param_types.len > 0 {
generic_param_types[i] } else { '' }
if p.tok != .comma { break }
generic_types[type_param] = if generic_param_types.len > 0 { generic_param_types[i] } else { '' }
if p.tok != .comma {
break
}
p.check(.comma)
}
p.check(.gt)
is_generic = true
}
is_generic_instance := is_generic && generic_param_types.len > 0
is_c := name == 'C' && p.tok == .dot
if is_c {
/*
@ -101,10 +102,12 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
p.gen_typedef('typedef $kind $name $name;')
}
// TODO: handle error
parser_idx := p.v.get_file_parser_index(p.file_path) or { 0 }
//if !p.scanner.is_vh {
// parser_idx = p.v.get_file_parser_index(p.file_path) or { panic('cant find parser idx for $p.file_path') }
//}
parser_idx := p.v.get_file_parser_index(p.file_path) or {
0
}
// if !p.scanner.is_vh {
// parser_idx = p.v.get_file_parser_index(p.file_path) or { panic('cant find parser idx for $p.file_path') }
// }
// Register the type
mut is_ph := false
if typ.is_placeholder {
@ -251,9 +254,14 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
// `pub` access mod
// access_mod := if is_pub_field { AccessMod.public } else { AccessMod.private}
p.fspace()
defer { if is_generic_instance { p.generic_dispatch=TypeInst{} } }
defer {
if is_generic_instance {
p.generic_dispatch = TypeInst{
}
}
}
if is_generic_instance {
p.generic_dispatch=TypeInst{
p.generic_dispatch = TypeInst{
inst: generic_types
}
}
@ -312,8 +320,7 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
did_gen_something = true
is_mut := access_mod in [.private_mut, .public_mut, .global]
if p.first_pass() || is_generic {
p.table.add_field(typ.name, field_name, field_type, is_mut,
attr, access_mod)
p.table.add_field(typ.name, field_name, field_type, is_mut, attr, access_mod)
}
p.fgen_nl() // newline between struct fields
}
@ -337,7 +344,6 @@ fn (p mut Parser) struct_init(typ_ string) string {
if !t.is_public && t.mod != p.mod {
p.warn('type `$t.name` is private')
}
// generic struct init
if p.peek() == .lt {
p.next()
@ -349,14 +355,15 @@ fn (p mut Parser) struct_init(typ_ string) string {
type_param = p.generic_dispatch.inst[type_param]
}
type_params << type_param
if p.tok != .comma { break }
if p.tok != .comma {
break
}
p.check(.comma)
}
p.dispatch_generic_struct(mut t, type_params)
t = p.table.find_type(t.name)
typ = t.name
}
if p.gen_struct_init(typ, &t) {
return typ
}
@ -500,7 +507,7 @@ fn (p mut Parser) dispatch_generic_struct(t mut Type, type_params []string) {
mut generic_types := map[string]string
if t.name in p.table.generic_struct_params {
mut i := 0
for _,v in p.table.generic_struct_params[t.name] {
for _, v in p.table.generic_struct_params[t.name] {
generic_types[v] = type_params[i]
i++
}
@ -510,7 +517,6 @@ fn (p mut Parser) dispatch_generic_struct(t mut Type, type_params []string) {
}
p.cgen.typedefs << 'typedef struct $t.name $t.name;\n'
}
mut gp := p.v.parsers[t.parser_idx]
gp.is_vgen = true
saved_state := p.save_state()