mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sort structs: handle fixed size arrays
This commit is contained in:
parent
576618d8cc
commit
88ec9c235d
@ -14,6 +14,9 @@ fn test_add() {
|
|||||||
assert a.ends_with('bbbbb')
|
assert a.ends_with('bbbbb')
|
||||||
a += '123'
|
a += '123'
|
||||||
assert a.ends_with('3')
|
assert a.ends_with('3')
|
||||||
|
mut foo := Foo{0, 'hi'}
|
||||||
|
foo.str += '!'
|
||||||
|
assert foo.str == 'hi!'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_ends_with() {
|
fn test_ends_with() {
|
||||||
@ -418,6 +421,8 @@ fn test_reverse() {
|
|||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
bar int
|
bar int
|
||||||
|
mut:
|
||||||
|
str string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (f Foo) baz() string {
|
fn (f Foo) baz() string {
|
||||||
@ -584,6 +589,7 @@ fn test_inter_before_comp_if() {
|
|||||||
$if linux {
|
$if linux {
|
||||||
println(s)
|
println(s)
|
||||||
}
|
}
|
||||||
|
assert s == '123'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_double_quote_inter() {
|
fn test_double_quote_inter() {
|
||||||
|
@ -376,19 +376,22 @@ fn sort_structs(types []Type) []Type {
|
|||||||
mut dep_graph := new_dep_graph()
|
mut dep_graph := new_dep_graph()
|
||||||
// types name list
|
// types name list
|
||||||
mut type_names := []string
|
mut type_names := []string
|
||||||
for t in types {
|
for typ in types {
|
||||||
type_names << t.name
|
type_names << typ.name
|
||||||
}
|
}
|
||||||
// loop over types
|
// loop over types
|
||||||
for t in types {
|
for t in types {
|
||||||
// create list of deps
|
// create list of deps
|
||||||
mut field_deps := []string
|
mut field_deps := []string
|
||||||
for field in t.fields {
|
for field in t.fields {
|
||||||
|
// Need to handle fixed size arrays as well (`[10]Point`)
|
||||||
|
ft := if field.typ.starts_with('[') { field.typ.all_after(']') }
|
||||||
|
else { field.typ }
|
||||||
// skip if not in types list or already in deps
|
// skip if not in types list or already in deps
|
||||||
if !(field.typ in type_names) || field.typ in field_deps {
|
if !(ft in type_names) || ft in field_deps {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
field_deps << field.typ
|
field_deps << ft//field.typ
|
||||||
}
|
}
|
||||||
// add type and dependant types to graph
|
// add type and dependant types to graph
|
||||||
dep_graph.add(t.name, field_deps)
|
dep_graph.add(t.name, field_deps)
|
||||||
|
@ -154,3 +154,26 @@ fn test_assoc_with_constants() {
|
|||||||
assert again.b == 22
|
assert again.b == 22
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
[typedef]
|
||||||
|
struct C.fixed {
|
||||||
|
points [10]C.point
|
||||||
|
}
|
||||||
|
|
||||||
|
[typedef]
|
||||||
|
struct C.point {
|
||||||
|
x int
|
||||||
|
y int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_fixed_field() {
|
||||||
|
f := &C.fixed{}
|
||||||
|
p := f.points[0]
|
||||||
|
//f.nums[0] = 10
|
||||||
|
//println(f.nums[0])
|
||||||
|
println(p.x)
|
||||||
|
//nums: [10]int
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user