Attempt to translate literal as the name of the simple macro it was expanded from.
fn checkLiteralMacro(t: *Translator, tok: TokenIndex, used: ResultUsed) !?ZigNode
fn checkLiteralMacro(t: *Translator, tok: TokenIndex, used: ResultUsed) !?ZigNode {
if (!t.keep_macro_literals) return null;
const expansion_locs = t.pp.expansionSlice(tok);
if (expansion_locs.len == 0) return null;
const last_expand = expansion_locs[0];
const source = t.comp.getSource(last_expand.id);
var tokenizer: aro.Tokenizer = .{
.buf = source.buf,
.langopts = t.comp.langopts,
.source = last_expand.id,
.index = last_expand.byte_offset,
.splice_locs = &.{},
};
const name_tok = tokenizer.next();
if (!name_tok.id.isMacroIdentifier()) return null;
const name = t.pp.tokSlice(name_tok);
if (t.global_scope.containsNow(name)) return null;
const macro = t.pp.defines.get(name) orelse return null;
if (macro.is_func) return null;
if (macro.isBuiltin()) return null;
var tok_count: u8 = 0;
for (macro.tokens) |macro_tok| {
switch (macro_tok.id) {
.invalid => continue,
.whitespace => continue,
.comment => continue,
.macro_ws => continue,
else => {
if (tok_count != 0) return null;
tok_count += 1;
},
}
}
if (t.checkTranslatableMacro(macro.tokens, macro.params) != null) return null;
const ident = try ZigTag.identifier.create(t.arena, name);
return try t.maybeSuppressResult(used, ident);
}