authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-07 15:45:29+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 10:36:38-04:00
log3fb030e78a04ff5eebd4e01769099b799912b9fd
tree03a90d6c75538257bb603a115b4203958f2f6abd
parent37e6a64690a257b4f5a9e3f234deb8b72e74ca54
signaturelock-open Commit is signed but in an unrecognized format.

std: use std.ArrayList(u8) instead of std.Buffer in src-self-hosted/translate_c.zig


1 files changed, 7 insertions(+), 6 deletions(-)

src-self-hosted/translate_c.zig+7-6
...@@ -209,7 +209,7 @@ const Scope = struct {...@@ -209,7 +209,7 @@ const Scope = struct {
209209
210pub const Context = struct {210pub const Context = struct {
211 tree: *ast.Tree,211 tree: *ast.Tree,
212 source_buffer: *std.Buffer,212 source_buffer: *std.ArrayList(u8),
213 err: Error,213 err: Error,
214 source_manager: *ZigClangSourceManager,214 source_manager: *ZigClangSourceManager,
215 decl_table: DeclTable,215 decl_table: DeclTable,
...@@ -296,7 +296,8 @@ pub fn translate(...@@ -296,7 +296,8 @@ pub fn translate(
296 .eof_token = undefined,296 .eof_token = undefined,
297 };297 };
298298
299 var source_buffer = try std.Buffer.initSize(arena, 0);299 var source_buffer = std.ArrayList(u8).init(arena);
300 errdefer source_buffer.deinit();
300301
301 var context = Context{302 var context = Context{
302 .tree = tree,303 .tree = tree,
...@@ -4309,7 +4310,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {...@@ -4309,7 +4310,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {
4309 return RestorePoint{4310 return RestorePoint{
4310 .c = c,4311 .c = c,
4311 .token_index = c.tree.tokens.len,4312 .token_index = c.tree.tokens.len,
4312 .src_buf_index = c.source_buffer.len(),4313 .src_buf_index = c.source_buffer.len,
4313 };4314 };
4314}4315}
43154316
...@@ -4771,11 +4772,11 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd...@@ -4771,11 +4772,11 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd
47714772
4772fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {4773fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
4773 assert(token_id != .Invalid);4774 assert(token_id != .Invalid);
4774 const start_index = c.source_buffer.len();4775 const start_index = c.source_buffer.len;
4775 errdefer c.source_buffer.shrink(start_index);4776 errdefer c.source_buffer.shrink(start_index);
47764777
4777 try c.source_buffer.outStream().print(format, args);4778 try c.source_buffer.outStream().print(format, args);
4778 const end_index = c.source_buffer.len();4779 const end_index = c.source_buffer.len;
4779 const token_index = c.tree.tokens.len;4780 const token_index = c.tree.tokens.len;
4780 const new_token = try c.tree.tokens.addOne();4781 const new_token = try c.tree.tokens.addOne();
4781 errdefer c.tree.tokens.shrink(token_index);4782 errdefer c.tree.tokens.shrink(token_index);
...@@ -4785,7 +4786,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8,...@@ -4785,7 +4786,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8,
4785 .start = start_index,4786 .start = start_index,
4786 .end = end_index,4787 .end = end_index,
4787 };4788 };
4788 try c.source_buffer.appendByte(' ');4789 try c.source_buffer.append(' ');
47894790
4790 return token_index;4791 return token_index;
4791}4792}