final vfmt run before CI check

pull/3182/head
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

@ -70,19 +70,19 @@ fresh_vc:
rm -rf $(TMPVC)
$(GITFASTCLONE) $(VCREPO) $(TMPVC)
#latest_tcc: $(TMPTCC)/.git/config
#ifndef ANDROID
#cd $(TMPTCC) && $(GITCLEANPULL)
#endif
latest_tcc: $(TMPTCC)/.git/config
ifndef ANDROID
cd $(TMPTCC) && $(GITCLEANPULL)
endif
#fresh_tcc:
#ifndef ANDROID
#rm -rf $(TMPTCC)
#$(GITFASTCLONE) $(TCCREPO) $(TMPTCC)
#endif
fresh_tcc:
ifndef ANDROID
rm -rf $(TMPTCC)
$(GITFASTCLONE) $(TCCREPO) $(TMPTCC)
endif
#$(TMPTCC)/.git/config:
#$(MAKE) fresh_tcc
$(TMPTCC)/.git/config:
$(MAKE) fresh_tcc
$(TMPVC)/.git/config:
$(MAKE) fresh_vc

View File

@ -400,3 +400,4 @@ fn C.WaitForSingleObject(voidptr, int) int
fn C.ReleaseMutex(voidptr) bool

View File

@ -480,12 +480,12 @@ fn (v &V) interface_table() string {
concrete_type_name := gen_type.replace('*', '_ptr')
sb.writeln('int _${interface_name}_${concrete_type_name}_index = $i;')
}
if t.gen_types.len > 0 {
// methods = '{TCCSKIP(0)}'
// }
sb.writeln('void* (* ${interface_name}_name_table[][$t.methods.len]) = ' + '{ \n $methods \n }; ')
}else{
}
else {
// The line below is needed so that C compilation succeeds,
// even if no interface methods are called.
// See https://github.com/zenith391/vgtk3/issues/7

View File

@ -227,7 +227,6 @@ fn (p mut Parser) name_expr() string {
p.string_expr()
return 'charptr'
}
// known_type := p.table.known_type(name)
orig_name := name
is_c := name == 'C' && p.peek() == .dot
@ -722,18 +721,13 @@ fn (p mut Parser) factor() string {
.key_offsetof {
p.next()
p.check(.lpar)
offsetof_typ := p.get_type()
p.check(.comma)
member := p.check_name()
p.check(.rpar)
p.gen('__offsetof($offsetof_typ, $member)')
return 'int'
}
.amp, .dot, .mul {
// (dot is for enum vals: `.green`)
return p.name_expr()

View File

@ -774,7 +774,9 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
for {
param_type := p.check_name()
generic_param_types << param_type
if p.tok != .comma { break }
if p.tok != .comma {
break
}
p.check(.comma)
}
p.check(.gt)
@ -1026,7 +1028,6 @@ fn (p mut Parser) fn_call_args(f mut Fn, generic_param_types []string) {
// if f.args[0].typ.ends_with('*') {
// p.gen('&/*119*/')
// }
// pos := p.cgen.cur_line.index('/* ? */')
// if pos > -1 {
// expr := p.cgen.cur_line[pos..]
@ -1037,8 +1038,6 @@ fn (p mut Parser) fn_call_args(f mut Fn, generic_param_types []string) {
// p.gen('}[0] ')
// }
// }
continue
}
// Reached the final vararg? Quit
@ -1520,7 +1519,9 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti &TypeInst) {
}
f.type_inst << *ti
p.table.register_fn(f)
if f.is_method { f.name = f.receiver_typ + '_' + f.name }
if f.is_method {
f.name = f.receiver_typ + '_' + f.name
}
rename_generic_fn_instance(mut f, ti)
replace_generic_type_params(mut f, ti)
// TODO: Handle case where type not defined yet, see above
@ -1543,7 +1544,8 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti &TypeInst) {
gp.generic_dispatch = *ti
gp.next()
gp.fn_decl()
gp.generic_dispatch = TypeInst{}
gp.generic_dispatch = TypeInst{
}
p.cgen.lines_extra << p.cgen.lines
p.restore_state(saved_state, false, true)
p.cgen.fns << '${p.fn_signature(f)};'

View File

@ -156,15 +156,13 @@ pub fn (v &V) finalize_compilation() {
pub fn (v mut V) add_parser(parser Parser) int {
pidx := v.parsers.len
v.parsers << parser
file_path := if filepath.is_abs(parser.file_path) {
parser.file_path } else { os.realpath(parser.file_path) }
file_path := if filepath.is_abs(parser.file_path) { parser.file_path } else { os.realpath(parser.file_path) }
v.file_parser_idx[file_path] = pidx
return pidx
}
pub fn (v &V) get_file_parser_index(file string) ?int {
file_path := if filepath.is_abs(file) {
file } else { os.realpath(file) }
file_path := if filepath.is_abs(file) { file } else { os.realpath(file) }
if file_path in v.file_parser_idx {
return v.file_parser_idx[file_path]
}

View File

@ -1100,7 +1100,9 @@ fn (p mut Parser) get_type() string {
if type_param in p.generic_dispatch.inst {
typ = '${typ}_' + p.generic_dispatch.inst[type_param]
}
if p.tok != .comma { break }
if p.tok != .comma {
break
}
p.check(.comma)
}
p.check(.gt)
@ -3020,7 +3022,9 @@ fn (p mut Parser) skip_block(inside_first_lcbr bool) {
}
if p.tok == .rcbr {
cbr_depth--
if cbr_depth == 0 { break }
if cbr_depth == 0 {
break
}
}
p.next()
}

View File

@ -889,3 +889,4 @@ fn (s &Scanner) validate_var_name(name string) {
s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ')
}
}

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,7 +41,6 @@ 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 {
@ -49,16 +50,16 @@ fn (p mut Parser) struct_decl(generic_param_types []string) {
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,7 +102,9 @@ 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 }
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') }
// }
@ -251,7 +254,12 @@ 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{
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
}
@ -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()