mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
[if vfmt] for fgen() functions
This commit is contained in:
parent
d81b0675f0
commit
d00fdca38f
@ -5,7 +5,7 @@
|
|||||||
module builtin
|
module builtin
|
||||||
|
|
||||||
struct Option {
|
struct Option {
|
||||||
data [255]byte
|
data [300]byte
|
||||||
error string
|
error string
|
||||||
ecode int
|
ecode int
|
||||||
ok bool
|
ok bool
|
||||||
@ -14,8 +14,8 @@ struct Option {
|
|||||||
|
|
||||||
// `fn foo() ?Foo { return foo }` => `fn foo() ?Foo { return opt_ok(foo); }`
|
// `fn foo() ?Foo { return foo }` => `fn foo() ?Foo { return opt_ok(foo); }`
|
||||||
fn opt_ok(data voidptr, size int) Option {
|
fn opt_ok(data voidptr, size int) Option {
|
||||||
if size >= 255 {
|
if size >= 300 {
|
||||||
panic('option size too big: $size (max is 255), this is a temporary limit')
|
panic('option size too big: $size (max is 300), this is a temporary limit')
|
||||||
}
|
}
|
||||||
res := Option {
|
res := Option {
|
||||||
ok: true
|
ok: true
|
||||||
|
@ -43,6 +43,7 @@ mut:
|
|||||||
dispatch_of TypeInst // current type inst of this generic instance
|
dispatch_of TypeInst // current type inst of this generic instance
|
||||||
body_idx int // idx of the first body statement
|
body_idx int // idx of the first body statement
|
||||||
fn_name_token_idx int // used by error reporting
|
fn_name_token_idx int // used by error reporting
|
||||||
|
comptime_define string
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TypeInst {
|
struct TypeInst {
|
||||||
@ -197,6 +198,7 @@ fn (p mut Parser) fn_decl() {
|
|||||||
is_public: p.tok == .key_pub || p.is_vh // functions defined in .vh are always public
|
is_public: p.tok == .key_pub || p.is_vh // functions defined in .vh are always public
|
||||||
is_unsafe: p.attr == 'unsafe_fn'
|
is_unsafe: p.attr == 'unsafe_fn'
|
||||||
is_deprecated: p.attr == 'deprecated'
|
is_deprecated: p.attr == 'deprecated'
|
||||||
|
comptime_define: if p.attr.starts_with('if ') { p.attr.right(3) } else { '' }
|
||||||
}
|
}
|
||||||
is_live := p.attr == 'live' && !p.pref.is_so && p.pref.is_live
|
is_live := p.attr == 'live' && !p.pref.is_so && p.pref.is_live
|
||||||
if p.attr == 'live' && p.first_pass() && !p.pref.is_live && !p.pref.is_so {
|
if p.attr == 'live' && p.first_pass() && !p.pref.is_live && !p.pref.is_so {
|
||||||
@ -677,6 +679,10 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
|
|||||||
}
|
}
|
||||||
p.error('function `$f.name` is private')
|
p.error('function `$f.name` is private')
|
||||||
}
|
}
|
||||||
|
is_comptime_define := f.comptime_define != '' && f.comptime_define != p.pref.comptime_define
|
||||||
|
if is_comptime_define {
|
||||||
|
p.cgen.nogen = true
|
||||||
|
}
|
||||||
p.calling_c = f.is_c
|
p.calling_c = f.is_c
|
||||||
if f.is_c && !p.builtin_mod {
|
if f.is_c && !p.builtin_mod {
|
||||||
if f.name == 'free' {
|
if f.name == 'free' {
|
||||||
@ -739,6 +745,9 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
|
|||||||
|
|
||||||
p.gen(')')
|
p.gen(')')
|
||||||
p.calling_c = false
|
p.calling_c = false
|
||||||
|
if is_comptime_define {
|
||||||
|
p.cgen.nogen = false
|
||||||
|
}
|
||||||
// println('end of fn call typ=$f.typ')
|
// println('end of fn call typ=$f.typ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1853,9 +1853,6 @@ fn (p mut Parser) var_expr(v Var) string {
|
|||||||
p.next()
|
p.next()
|
||||||
mut typ := v.typ
|
mut typ := v.typ
|
||||||
// Function pointer?
|
// Function pointer?
|
||||||
|
|
||||||
//println('CALLING FN PTR')
|
|
||||||
//p.print_tok()
|
|
||||||
if typ.starts_with('fn ') && p.tok == .lpar {
|
if typ.starts_with('fn ') && p.tok == .lpar {
|
||||||
T := p.table.find_type(typ)
|
T := p.table.find_type(typ)
|
||||||
p.gen('(')
|
p.gen('(')
|
||||||
@ -2038,7 +2035,7 @@ struct $typ.name {
|
|||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
p.fn_call(mut method, method_ph, '', str_typ)
|
p.fn_call(mut method, method_ph, '', str_typ)
|
||||||
// Methods returning `array` should return `array_string`
|
// Methods returning `array` should return `array_string` etc
|
||||||
if method.typ == 'array' && typ.name.starts_with('array_') {
|
if method.typ == 'array' && typ.name.starts_with('array_') {
|
||||||
return typ.name
|
return typ.name
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ fn (scanner mut Scanner) fgen(s_ string) {
|
|||||||
scanner.fmt_line_empty = false
|
scanner.fmt_line_empty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (scanner mut Scanner) fgenln(s_ string) {
|
fn (scanner mut Scanner) fgenln(s_ string) {
|
||||||
mut s := s_
|
mut s := s_
|
||||||
if scanner.fmt_line_empty {
|
if scanner.fmt_line_empty {
|
||||||
@ -26,14 +27,17 @@ fn (scanner mut Scanner) fgenln(s_ string) {
|
|||||||
scanner.fmt_line_empty = true
|
scanner.fmt_line_empty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (p mut Parser) fgen(s string) {
|
fn (p mut Parser) fgen(s string) {
|
||||||
p.scanner.fgen(s)
|
p.scanner.fgen(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (p mut Parser) fspace() {
|
fn (p mut Parser) fspace() {
|
||||||
p.fgen(' ')
|
p.fgen(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (p mut Parser) fgenln(s string) {
|
fn (p mut Parser) fgenln(s string) {
|
||||||
p.scanner.fgenln(s)
|
p.scanner.fgenln(s)
|
||||||
}
|
}
|
||||||
@ -51,10 +55,12 @@ fn (p mut Parser) peek() TokenKind {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (p mut Parser) fmt_inc() {
|
fn (p mut Parser) fmt_inc() {
|
||||||
p.scanner.fmt_indent++
|
p.scanner.fmt_indent++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[if vfmt]
|
||||||
fn (p mut Parser) fmt_dec() {
|
fn (p mut Parser) fmt_dec() {
|
||||||
p.scanner.fmt_indent--
|
p.scanner.fmt_indent--
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user