| ... | ... | @@ -34,6 +34,8 @@ pub const CValue = union(enum) { |
| 34 | 34 | /// By-value |
| 35 | 35 | decl: *Decl, |
| 36 | 36 | decl_ref: *Decl, |
| 37 | /// Render the slice as an identifier (using fmtIdent) |
| 38 | identifier: []const u8, |
| 37 | 39 | /// Render these bytes literally. |
| 38 | 40 | /// TODO make this a [*:0]const u8 to save memory |
| 39 | 41 | bytes: []const u8, |
| ... | ... | @@ -78,6 +80,7 @@ fn formatIdent( |
| 78 | 80 | ) !void { |
| 79 | 81 | _ = fmt; |
| 80 | 82 | _ = options; |
| 83 | try writer.writeAll("__"); // Add double underscore to avoid conflicting with C's reserved keywords |
| 81 | 84 | for (ident) |c, i| { |
| 82 | 85 | switch (c) { |
| 83 | 86 | 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c), |
| ... | ... | @@ -741,7 +744,7 @@ pub const DeclGen = struct { |
| 741 | 744 | if (!field_ty.hasCodeGenBits()) continue; |
| 742 | 745 | |
| 743 | 746 | const alignment = entry.value_ptr.abi_align; |
| 744 | | const name: CValue = .{ .bytes = entry.key_ptr.* }; |
| 747 | const name: CValue = .{ .identifier = entry.key_ptr.* }; |
| 745 | 748 | try buffer.append(' '); |
| 746 | 749 | try dg.renderTypeAndName(buffer.writer(), field_ty, name, .Mut, alignment); |
| 747 | 750 | try buffer.appendSlice(";\n"); |
| ... | ... | @@ -1033,6 +1036,7 @@ pub const DeclGen = struct { |
| 1033 | 1036 | try w.writeByte('&'); |
| 1034 | 1037 | return dg.renderDeclName(decl, w); |
| 1035 | 1038 | }, |
| 1039 | .identifier => |ident| return w.print("{}", .{fmtIdent(ident)}), |
| 1036 | 1040 | .bytes => |bytes| return w.writeAll(bytes), |
| 1037 | 1041 | } |
| 1038 | 1042 | } |