parent
f1797a0150
commit
63f835c4ce
|
@ -760,6 +760,32 @@ pub fn (mut g Gen) write_typedef_types() {
|
||||||
.array {
|
.array {
|
||||||
g.type_definitions.writeln('typedef array $typ.cname;')
|
g.type_definitions.writeln('typedef array $typ.cname;')
|
||||||
}
|
}
|
||||||
|
.array_fixed {
|
||||||
|
info := typ.info as table.ArrayFixed
|
||||||
|
elem_sym := g.table.get_type_symbol(info.elem_type)
|
||||||
|
if elem_sym.is_builtin() {
|
||||||
|
// .array_fixed {
|
||||||
|
styp := typ.cname
|
||||||
|
// array_fixed_char_300 => char x[300]
|
||||||
|
mut fixed := styp[12..]
|
||||||
|
len := styp.after('_')
|
||||||
|
fixed = fixed[..fixed.len - len.len - 1]
|
||||||
|
if fixed.starts_with('C__') {
|
||||||
|
fixed = fixed[3..]
|
||||||
|
}
|
||||||
|
if elem_sym.info is table.FnType {
|
||||||
|
pos := g.out.len
|
||||||
|
g.write_fn_ptr_decl(&elem_sym.info, '')
|
||||||
|
fixed = g.out.after(pos)
|
||||||
|
g.out.go_back(fixed.len)
|
||||||
|
mut def_str := 'typedef $fixed;'
|
||||||
|
def_str = def_str.replace_once('(*)', '(*$styp[$len])')
|
||||||
|
g.type_definitions.writeln(def_str)
|
||||||
|
} else {
|
||||||
|
g.type_definitions.writeln('typedef $fixed $styp [$len];')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.interface_ {
|
.interface_ {
|
||||||
g.write_interface_typesymbol_declaration(typ)
|
g.write_interface_typesymbol_declaration(typ)
|
||||||
}
|
}
|
||||||
|
@ -5419,27 +5445,28 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
|
||||||
g.type_definitions.writeln('')
|
g.type_definitions.writeln('')
|
||||||
}
|
}
|
||||||
table.ArrayFixed {
|
table.ArrayFixed {
|
||||||
// .array_fixed {
|
elem_sym := g.table.get_type_symbol(typ.info.elem_type)
|
||||||
styp := typ.cname
|
if !elem_sym.is_builtin() {
|
||||||
// array_fixed_char_300 => char x[300]
|
// .array_fixed {
|
||||||
mut fixed := styp[12..]
|
styp := typ.cname
|
||||||
len := styp.after('_')
|
// array_fixed_char_300 => char x[300]
|
||||||
fixed = fixed[..fixed.len - len.len - 1]
|
mut fixed := styp[12..]
|
||||||
if fixed.starts_with('C__') {
|
len := styp.after('_')
|
||||||
fixed = fixed[3..]
|
fixed = fixed[..fixed.len - len.len - 1]
|
||||||
}
|
if fixed.starts_with('C__') {
|
||||||
elem_type := typ.info.elem_type
|
fixed = fixed[3..]
|
||||||
elem_sym := g.table.get_type_symbol(elem_type)
|
}
|
||||||
if elem_sym.info is table.FnType {
|
if elem_sym.info is table.FnType {
|
||||||
pos := g.out.len
|
pos := g.out.len
|
||||||
g.write_fn_ptr_decl(&elem_sym.info, '')
|
g.write_fn_ptr_decl(&elem_sym.info, '')
|
||||||
fixed = g.out.after(pos)
|
fixed = g.out.after(pos)
|
||||||
g.out.go_back(fixed.len)
|
g.out.go_back(fixed.len)
|
||||||
mut def_str := 'typedef $fixed;'
|
mut def_str := 'typedef $fixed;'
|
||||||
def_str = def_str.replace_once('(*)', '(*$styp[$len])')
|
def_str = def_str.replace_once('(*)', '(*$styp[$len])')
|
||||||
g.type_definitions.writeln(def_str)
|
g.type_definitions.writeln(def_str)
|
||||||
} else {
|
} else {
|
||||||
g.type_definitions.writeln('typedef $fixed $styp [$len];')
|
g.type_definitions.writeln('typedef $fixed $styp [$len];')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
type Block = [8]byte
|
||||||
|
|
||||||
|
fn test_alias_fixed_array() {
|
||||||
|
a := [8]byte{init: 22}
|
||||||
|
ret := get(Block(a))
|
||||||
|
println(ret)
|
||||||
|
assert ret == 'Block([22, 22, 22, 22, 22, 22, 22, 22])'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get(b Block) string {
|
||||||
|
return '$b'
|
||||||
|
}
|
Loading…
Reference in New Issue