Fix (gen.c) -> Fixed attribute without its value is now an error

pull/14027/head
Shib 2022-04-13 15:03:36 +02:00
parent 50e4ca9c31
commit 8ade188e0d
4 changed files with 12 additions and 16 deletions

View File

@ -1349,9 +1349,7 @@ pub fn (mut g Gen) write_fn_typesymbol_declaration(sym ast.TypeSymbol) {
for attr in func.attrs {
match attr.name {
'callconv' {
if attr.has_arg {
call_conv = '__$attr.arg '
}
call_conv = '__$attr.arg '
}
else {}
}

View File

@ -2154,9 +2154,7 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string {
fn_attrs += '__fastcall '
}
"callconv" {
if attr.has_arg {
fn_attrs += '__$attr.arg '
}
fn_attrs += '__$attr.arg '
}
'console' {
g.force_main_console = true

View File

@ -230,11 +230,11 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
p.tok.pos())
}
'callconv' {
if fna.has_arg {
if fna.arg !in ['stdcall', 'fastcall', 'cdecl'] {
p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl',
p.tok.pos())
}
if !fna.has_arg {
p.error_with_pos('callconv attribute is present but its value is missing', p.prev_tok.pos())
}
if fna.arg !in ['stdcall', 'fastcall', 'cdecl'] {
p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', p.prev_tok.pos())
}
}
else {}

View File

@ -233,11 +233,11 @@ pub fn (mut p Parser) parse_fn_type(name string) ast.Type {
for attr in p.attrs {
match attr.name {
'callconv' {
if attr.has_arg {
if attr.arg !in ['stdcall', 'fastcall', 'cdecl'] {
p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl',
p.prev_tok.pos())
}
if !attr.has_arg {
p.error_with_pos('callconv attribute is present but its value is missing', p.prev_tok.pos())
}
if attr.arg !in ['stdcall', 'fastcall', 'cdecl'] {
p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', p.prev_tok.pos())
}
}
else {}