| ... | @@ -601,9 +601,8 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us | ... | @@ -601,9 +601,8 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us |
| 601 | const operand = operands[field_index]; | 601 | const operand = operands[field_index]; |
| 602 | | 602 | |
| 603 | // Should be enough for all names - adjust as needed. | 603 | // Should be enough for all names - adjust as needed. |
| 604 | var name_buffer = std.BoundedArray(u8, 64){ | 604 | var name_backing_buffer: [64]u8 = undefined; |
| 605 | .buffer = undefined, | 605 | var name_buffer = std.ArrayListUnmanaged(u8).initBuffer(&name_backing_buffer); |
| 606 | }; | | |
| 607 | | 606 | |
| 608 | derive_from_kind: { | 607 | derive_from_kind: { |
| 609 | // Operand names are often in the json encoded as "'Name'" (with two sets of quotes). | 608 | // Operand names are often in the json encoded as "'Name'" (with two sets of quotes). |
| ... | @@ -617,33 +616,33 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us | ... | @@ -617,33 +616,33 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us |
| 617 | // Use the same loop to transform to snake-case. | 616 | // Use the same loop to transform to snake-case. |
| 618 | for (name) |c| { | 617 | for (name) |c| { |
| 619 | switch (c) { | 618 | switch (c) { |
| 620 | 'a'...'z', '0'...'9' => try name_buffer.append(c), | 619 | 'a'...'z', '0'...'9' => name_buffer.appendAssumeCapacity(c), |
| 621 | 'A'...'Z' => try name_buffer.append(std.ascii.toLower(c)), | 620 | 'A'...'Z' => name_buffer.appendAssumeCapacity(std.ascii.toLower(c)), |
| 622 | ' ', '~' => try name_buffer.append('_'), | 621 | ' ', '~' => name_buffer.appendAssumeCapacity('_'), |
| 623 | else => break :derive_from_kind, | 622 | else => break :derive_from_kind, |
| 624 | } | 623 | } |
| 625 | } | 624 | } |
| 626 | | 625 | |
| 627 | // Assume there are no duplicate 'name' fields. | 626 | // Assume there are no duplicate 'name' fields. |
| 628 | try writer.print("{}", .{std.zig.fmtId(name_buffer.slice())}); | 627 | try writer.print("{}", .{std.zig.fmtId(name_buffer.items)}); |
| 629 | return; | 628 | return; |
| 630 | } | 629 | } |
| 631 | | 630 | |
| 632 | // Translate to snake case. | 631 | // Translate to snake case. |
| 633 | name_buffer.len = 0; | 632 | name_buffer.items.len = 0; |
| 634 | for (operand.kind, 0..) |c, i| { | 633 | for (operand.kind, 0..) |c, i| { |
| 635 | switch (c) { | 634 | switch (c) { |
| 636 | 'a'...'z', '0'...'9' => try name_buffer.append(c), | 635 | 'a'...'z', '0'...'9' => name_buffer.appendAssumeCapacity(c), |
| 637 | 'A'...'Z' => if (i > 0 and std.ascii.isLower(operand.kind[i - 1])) { | 636 | 'A'...'Z' => if (i > 0 and std.ascii.isLower(operand.kind[i - 1])) { |
| 638 | try name_buffer.appendSlice(&[_]u8{ '_', std.ascii.toLower(c) }); | 637 | name_buffer.appendSliceAssumeCapacity(&[_]u8{ '_', std.ascii.toLower(c) }); |
| 639 | } else { | 638 | } else { |
| 640 | try name_buffer.append(std.ascii.toLower(c)); | 639 | name_buffer.appendAssumeCapacity(std.ascii.toLower(c)); |
| 641 | }, | 640 | }, |
| 642 | else => unreachable, // Assume that the name is valid C-syntax (and contains no underscores). | 641 | else => unreachable, // Assume that the name is valid C-syntax (and contains no underscores). |
| 643 | } | 642 | } |
| 644 | } | 643 | } |
| 645 | | 644 | |
| 646 | try writer.print("{}", .{std.zig.fmtId(name_buffer.slice())}); | 645 | try writer.print("{}", .{std.zig.fmtId(name_buffer.items)}); |
| 647 | | 646 | |
| 648 | // For fields derived from type name, there could be any amount. | 647 | // For fields derived from type name, there could be any amount. |
| 649 | // Simply check against all other fields, and if another similar one exists, add a number. | 648 | // Simply check against all other fields, and if another similar one exists, add a number. |