1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: stabilise the attribute sorting order (sort first by length of atributes, then in alphabetical order of their names)

This commit is contained in:
Delyan Angelov 2022-04-14 14:52:59 +03:00
parent f1f75897b3
commit bf62b2e33e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 6 additions and 3 deletions

View File

@ -7,8 +7,11 @@ import v.ast
pub fn (mut f Fmt) attrs(attrs []ast.Attr) { pub fn (mut f Fmt) attrs(attrs []ast.Attr) {
mut sorted_attrs := attrs.clone() mut sorted_attrs := attrs.clone()
// Sort the attributes. The ones with arguments come first. // Sort the attributes. The ones with arguments come first
sorted_attrs.sort(a.arg.len > b.arg.len) sorted_attrs.sort_with_compare(fn (a &ast.Attr, b &ast.Attr) int {
d := b.arg.len - a.arg.len
return if d != 0 { d } else { compare_strings(b.arg, a.arg) }
})
for i, attr in sorted_attrs { for i, attr in sorted_attrs {
if attr.arg.len == 0 { if attr.arg.len == 0 {
f.single_line_attrs(sorted_attrs[i..]) f.single_line_attrs(sorted_attrs[i..])

View File

@ -13,8 +13,8 @@ pub fn test_tatltuae() int {
return test.foo + test.bar return test.foo + test.bar
} }
[export: DllMain]
[callconv: stdcall] [callconv: stdcall]
[export: DllMain]
fn main(hinst voidptr, fdw_reason int, lp_reserved voidptr) bool { fn main(hinst voidptr, fdw_reason int, lp_reserved voidptr) bool {
match fdw_reason { match fdw_reason {
C.DLL_PROCESS_ATTACH { C.DLL_PROCESS_ATTACH {