mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vh gen: consts before fns
This commit is contained in:
parent
92185a1a6f
commit
b298b397dc
@ -41,6 +41,8 @@ fn generate_vh(mod string) {
|
|||||||
println(filtered)
|
println(filtered)
|
||||||
mut v := new_v(['foo.v'])
|
mut v := new_v(['foo.v'])
|
||||||
//v.pref.generating_vh = true
|
//v.pref.generating_vh = true
|
||||||
|
mut consts := strings.new_builder(100)
|
||||||
|
mut fns := strings.new_builder(100)
|
||||||
for file in filtered {
|
for file in filtered {
|
||||||
mut p := v.new_parser_from_file(file)
|
mut p := v.new_parser_from_file(file)
|
||||||
p.scanner.is_vh = true
|
p.scanner.is_vh = true
|
||||||
@ -50,24 +52,27 @@ fn generate_vh(mod string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
match tok.tok {
|
match tok.tok {
|
||||||
TokenKind.key_fn { generate_fn(out, p.tokens, i) }
|
TokenKind.key_fn { fns.writeln(generate_fn(p.tokens, i)) }
|
||||||
TokenKind.key_const { generate_const(out, p.tokens, i) }
|
TokenKind.key_const { consts.writeln(generate_const(p.tokens, i)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result := consts.str() + fns.str().replace('\n\n', '')
|
||||||
|
out.writeln(result.replace('[ ]', '[]').replace('? ', '?'))
|
||||||
|
out.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_fn(file os.File, tokens []Token, i int) {
|
fn generate_fn(tokens []Token, i int) string {
|
||||||
mut out := strings.new_builder(100)
|
mut out := strings.new_builder(100)
|
||||||
mut next := tokens[i+1]
|
mut next := tokens[i+1]
|
||||||
if tokens[i-1].tok != .key_pub {
|
if tokens[i-1].tok != .key_pub {
|
||||||
// Skip private fns
|
// Skip private fns
|
||||||
return
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
if next.tok == .name && next.lit == 'C' {
|
if next.tok == .name && next.lit == 'C' {
|
||||||
println('skipping C')
|
println('skipping C')
|
||||||
return
|
return ''
|
||||||
}
|
}
|
||||||
//out.write('pub ')
|
//out.write('pub ')
|
||||||
mut tok := tokens[i]
|
mut tok := tokens[i]
|
||||||
@ -82,10 +87,10 @@ fn generate_fn(file os.File, tokens []Token, i int) {
|
|||||||
i++
|
i++
|
||||||
tok = tokens[i]
|
tok = tokens[i]
|
||||||
}
|
}
|
||||||
file.writeln(out.str())
|
return out.str()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_const(file os.File, tokens []Token, i int) {
|
fn generate_const(tokens []Token, i int) string {
|
||||||
mut out := strings.new_builder(100)
|
mut out := strings.new_builder(100)
|
||||||
mut tok := tokens[i]
|
mut tok := tokens[i]
|
||||||
for i < tokens.len && tok.tok != .rpar {
|
for i < tokens.len && tok.tok != .rpar {
|
||||||
@ -93,13 +98,12 @@ fn generate_const(file os.File, tokens []Token, i int) {
|
|||||||
out.write(' ')
|
out.write(' ')
|
||||||
if tokens[i+2].tok == .assign {
|
if tokens[i+2].tok == .assign {
|
||||||
out.write('\n\t')
|
out.write('\n\t')
|
||||||
|
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
tok = tokens[i]
|
tok = tokens[i]
|
||||||
}
|
}
|
||||||
out.writeln('\n)')
|
out.writeln('\n)')
|
||||||
file.writeln(out.str())
|
return out.str()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user