Skip to content

Commit

Permalink
Fix issue with anon structs in arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Nov 4, 2023
1 parent dcaa30b commit 3294b99
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/odin/format/format.odin
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ format :: proc(

ok := parser.parse_file(&p, &file)

fmt.println(file.syntax_error_count)

if !ok || file.syntax_error_count > 0 {
return {}, false
}
Expand Down
19 changes: 12 additions & 7 deletions src/odin/printer/visit.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ visit_expr :: proc(
}

if v.type != nil {
document = cons_with_nopl(document, visit_expr(p, v.type))
document = cons_with_nopl(document, group(visit_expr(p, v.type)))

if matrix_type, ok := v.type.derived.(^ast.Matrix_Type);
ok && len(v.elems) > 0 && is_matrix_type_constant(matrix_type) {
Expand Down Expand Up @@ -2081,16 +2081,21 @@ visit_expr :: proc(
} else {
document = cons(
document,
text("{"),
nest(
group(
cons(
if_break(" "),
text("{"),
nest(
cons(
break_with(""),
visit_exprs(p, v.elems, {.Add_Comma, .Group}),
),
),
if_break(","),
break_with(""),
visit_exprs(p, v.elems, {.Add_Comma, .Group}),
text("}"),
),
),
if_break(","),
break_with(""),
text("}"),
)
document = group(document)
}
Expand Down
16 changes: 8 additions & 8 deletions tools/odinfmt/tests/.snapshots/calls.odin
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ calls :: proc() {

result = vk.CreateInsance(
my_really_cool_call(
T{
T {
aaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
cccccccccccccccccccccccccccccccc,
Expand All @@ -89,7 +89,7 @@ calls :: proc() {
)
result = vk.CreateInsance(
my_really_cool_call(
T{
T {
a = aaaaaaaaaaaaaaaaaaaaa,
b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
c = cccccccccccccccccccccccccccccccc,
Expand All @@ -99,7 +99,7 @@ calls :: proc() {
)
result = vk.CreateInsance(
my_really_cool_call(
T{
T {
aaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
cccccccccccccccccccccccccccccccc,
Expand All @@ -111,7 +111,7 @@ calls :: proc() {
)
result = vk.CreateInsance(
my_really_cool_call(
T{
T {
a = aaaaaaaaaaaaaaaaaaaaa,
b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
c = cccccccccccccccccccccccccccccccc,
Expand All @@ -122,7 +122,7 @@ calls :: proc() {
)
result = vk.CreateInsance(
my_really_cool_call(
T{
T {
a = aaaaaaaaaaaaaaaaaaaaa,
b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
c = cccccccccccccccccccccccccccccccc,
Expand Down Expand Up @@ -152,7 +152,7 @@ calls :: proc() {
})

test_2(
Foo{
Foo {
field1 = 1,
field2 = "hello",
field3 = 1,
Expand All @@ -169,7 +169,7 @@ calls :: proc() {
})

test3(
Foo{
Foo {
field1 = 1,
field2 = "hello",
field3 = 1,
Expand All @@ -185,7 +185,7 @@ calls :: proc() {

resuuuuuuuuult := add_to_long_list_of_values(
fooooooooooooo,
Foo{
Foo {
field1 = 1,
field2 = "hello",
field3 = 1,
Expand Down
36 changes: 18 additions & 18 deletions tools/odinfmt/tests/random/.snapshots/document.odin
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
case Document_Cons:
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.rhs,
Expand All @@ -302,7 +302,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
)
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.lhs,
Expand All @@ -312,7 +312,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
case Document_Align:
append(
list,
Tuple{
Tuple {
indentation = 0,
mode = data.mode,
document = v.document,
Expand All @@ -322,7 +322,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
case Document_Nest:
append(
list,
Tuple{
Tuple {
indentation = data.indentation + v.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -345,7 +345,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
if data.mode == .Break {
append(
list,
Tuple{
Tuple {
indentation = data.indentation + v.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -355,7 +355,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
} else {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -366,7 +366,7 @@ fits :: proc(width: int, list: ^[dynamic]Tuple) -> bool {
case Document_Group:
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.document,
Expand Down Expand Up @@ -430,7 +430,7 @@ format :: proc(
case Document_Cons:
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.rhs,
Expand All @@ -439,7 +439,7 @@ format :: proc(
)
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.lhs,
Expand All @@ -449,7 +449,7 @@ format :: proc(
case Document_Nest:
append(
list,
Tuple{
Tuple {
indentation = data.indentation + v.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -459,7 +459,7 @@ format :: proc(
case Document_Align:
append(
list,
Tuple{
Tuple {
indentation = 0,
mode = data.mode,
document = v.document,
Expand Down Expand Up @@ -492,7 +492,7 @@ format :: proc(
if mode == .Break {
append(
list,
Tuple{
Tuple {
indentation = data.indentation + v.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -502,7 +502,7 @@ format :: proc(
} else {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = data.mode,
document = v.document,
Expand All @@ -519,7 +519,7 @@ format :: proc(

append(
&l,
Tuple{
Tuple {
indentation = data.indentation,
mode = .Flat,
document = v.document,
Expand All @@ -530,7 +530,7 @@ format :: proc(
if data.mode == .Fit {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = .Fit,
document = v.document,
Expand All @@ -540,7 +540,7 @@ format :: proc(
} else if fits(width - consumed, &l) && v.mode != .Break {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = .Flat,
document = v.document,
Expand All @@ -551,7 +551,7 @@ format :: proc(
if v.mode == .Fit {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = .Fit,
document = v.document,
Expand All @@ -561,7 +561,7 @@ format :: proc(
} else {
append(
list,
Tuple{
Tuple {
indentation = data.indentation,
mode = .Break,
document = v.document,
Expand Down

0 comments on commit 3294b99

Please sign in to comment.