mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 12:48:14 +00:00
refractor
This commit is contained in:
@@ -616,6 +616,13 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
largest := 0;
|
largest := 0;
|
||||||
case_count := 0;
|
case_count := 0;
|
||||||
|
|
||||||
|
TokenAndLength :: struct {
|
||||||
|
format_token: ^Format_Token,
|
||||||
|
length: int,
|
||||||
|
};
|
||||||
|
|
||||||
|
format_tokens := make([dynamic] TokenAndLength, 0, brace_token.parameter_count, context.temp_allocator);
|
||||||
|
|
||||||
//find all the switch cases that are one lined
|
//find all the switch cases that are one lined
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
|
|
||||||
@@ -623,7 +630,7 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
colon_found := false;
|
colon_found := false;
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
|
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
@@ -631,6 +638,7 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
|
|
||||||
//this will only happen if the case is one lined
|
//this will only happen if the case is one lined
|
||||||
if case_found && colon_found {
|
if case_found && colon_found {
|
||||||
|
append(&format_tokens, TokenAndLength { format_token = &line.format_tokens[i], length = length });
|
||||||
largest = max(length, largest);
|
largest = max(length, largest);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -650,38 +658,10 @@ align_switch_stmt :: proc(p: ^Printer, index: int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case_count = 0;
|
for token in format_tokens {
|
||||||
|
token.format_token.spaces_before = largest - token.length + 1;
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
|
||||||
case_found := false;
|
|
||||||
colon_found := false;
|
|
||||||
length := 0;
|
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
|
||||||
if format_token.kind == .Comment {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//this will only happen if the case is one lined
|
|
||||||
if case_found && colon_found {
|
|
||||||
line.format_tokens[i].spaces_before = (largest - length) + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if format_token.kind == .Case {
|
|
||||||
case_found = true;
|
|
||||||
case_count += 1;
|
|
||||||
} else if format_token.kind == .Colon {
|
|
||||||
colon_found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
length += len(format_token.text) + format_token.spaces_before;
|
|
||||||
}
|
|
||||||
|
|
||||||
if case_count >= brace_token.parameter_count {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
align_enum :: proc(p: ^Printer, index: int) {
|
align_enum :: proc(p: ^Printer, index: int) {
|
||||||
@@ -710,15 +690,23 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
largest := 0;
|
largest := 0;
|
||||||
comma_count := 0;
|
comma_count := 0;
|
||||||
|
|
||||||
|
TokenAndLength :: struct {
|
||||||
|
format_token: ^Format_Token,
|
||||||
|
length: int,
|
||||||
|
};
|
||||||
|
|
||||||
|
format_tokens := make([dynamic] TokenAndLength, 0, brace_token.parameter_count, context.temp_allocator);
|
||||||
|
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
for line, line_index in p.lines[brace_line + 1:] {
|
||||||
length := 0;
|
length := 0;
|
||||||
|
|
||||||
for format_token in line.format_tokens {
|
for format_token, i in line.format_tokens {
|
||||||
if format_token.kind == .Comment {
|
if format_token.kind == .Comment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if format_token.kind == .Eq {
|
if format_token.kind == .Eq {
|
||||||
|
append(&format_tokens, TokenAndLength { format_token = &line.format_tokens[i], length = length });
|
||||||
largest = max(length, largest);
|
largest = max(length, largest);
|
||||||
break;
|
break;
|
||||||
} else if format_token.kind == .Comma {
|
} else if format_token.kind == .Comma {
|
||||||
@@ -733,30 +721,10 @@ align_enum :: proc(p: ^Printer, index: int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comma_count = 0;
|
for token in format_tokens {
|
||||||
|
token.format_token.spaces_before = largest - token.length + 1;
|
||||||
for line, line_index in p.lines[brace_line + 1:] {
|
|
||||||
length := 0;
|
|
||||||
|
|
||||||
for format_token, i in line.format_tokens {
|
|
||||||
if format_token.kind == .Comment {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if format_token.kind == .Eq {
|
|
||||||
line.format_tokens[i].spaces_before = largest - length + 1;
|
|
||||||
break;
|
|
||||||
} else if format_token.kind == .Comma {
|
|
||||||
comma_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
length += len(format_token.text) + format_token.spaces_before;
|
|
||||||
}
|
|
||||||
|
|
||||||
if comma_count >= brace_token.parameter_count {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
align_struct :: proc(p: ^Printer, index: int) {
|
align_struct :: proc(p: ^Printer, index: int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user