diff options
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Module.zig b/src/Module.zig index ccf6996cae..933917d948 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4582,28 +4582,39 @@ pub fn optimizeMode(mod: Module) std.builtin.Mode { /// Otherwise, returns a reference to the source code bytes directly. /// See also `appendIdentStr` and `parseStrLit`. pub fn identifierTokenString(mod: *Module, scope: *Scope, token: ast.TokenIndex) InnerError![]const u8 { - return mod.identifierTokenStringTreeArena(scope, token, scope.tree(), scope.arena()); + const tree = scope.tree(); + const token_tags = tree.tokens.items(.tag); + assert(token_tags[token] == .identifier); + const ident_name = tree.tokenSlice(token); + if (!mem.startsWith(u8, ident_name, "@")) { + return ident_name; + } + var buf: ArrayListUnmanaged(u8) = .{}; + defer buf.deinit(mod.gpa); + try parseStrLit(mod, scope, token, &buf, ident_name, 1); + const duped = try scope.arena().dupe(u8, buf.items); + return duped; } /// `scope` is only used for error reporting. +/// The string is stored in `arena` regardless of whether it uses @"" syntax. pub fn identifierTokenStringTreeArena( mod: *Module, scope: *Scope, token: ast.TokenIndex, tree: *const ast.Tree, arena: *Allocator, -) InnerError![]const u8 { +) InnerError![]u8 { const token_tags = tree.tokens.items(.tag); assert(token_tags[token] == .identifier); const ident_name = tree.tokenSlice(token); if (!mem.startsWith(u8, ident_name, "@")) { - return ident_name; + return arena.dupe(u8, ident_name); } var buf: ArrayListUnmanaged(u8) = .{}; defer buf.deinit(mod.gpa); try parseStrLit(mod, scope, token, &buf, ident_name, 1); - const duped = try arena.dupe(u8, buf.items); - return duped; + return arena.dupe(u8, buf.items); } /// Given an identifier token, obtain the string for it (possibly parsing as a string |
