Skip to content

Commit

Permalink
Expand - Tweaked builtin macros slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Dec 3, 2023
1 parent b19269d commit 1bc671d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/expand/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class CExpander_assert:
else if( tok == TOK_EOF )
{
::std::stringstream ss;
ss << "assertion failed: ";
n->print(ss);

toks.push_back( Token(InterpolatedFragment(InterpolatedFragment::EXPR, n.release())) );
Expand All @@ -93,6 +92,8 @@ class CExpander_assert:
toks.push_back( Token(TOK_IDENT, RcString::new_interned("panic")) );
toks.push_back( Token(TOK_EXCLAM) );
toks.push_back( Token(TOK_PAREN_OPEN) );
toks.push_back( Token(TOK_STRING, std::string("assertion failed: {}")) );
toks.push_back( Token(TOK_COMMA) );
toks.push_back( Token(TOK_STRING, ss.str()) );
toks.push_back( Token(TOK_PAREN_CLOSE) );
}
Expand Down
14 changes: 14 additions & 0 deletions src/expand/format_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,19 @@ class CFormatArgsExpander:
return expand_format_args(sp, crate, lex, /*add_newline=*/false);
}
};
class CConstFormatArgsExpander:
public ExpandProcMacro
{
::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const TokenTree& tt, AST::Module& mod) override
{
Token tok;

auto lex = TTStream(sp, ParseState(), tt);
lex.parse_state().module = &mod;

return expand_format_args(sp, crate, lex, /*add_newline=*/false);
}
};

class CFormatArgsNlExpander:
public ExpandProcMacro
Expand All @@ -872,5 +885,6 @@ class CFormatArgsNlExpander:
};

STATIC_MACRO("format_args", CFormatArgsExpander);
STATIC_MACRO("const_format_args", CConstFormatArgsExpander);
STATIC_MACRO("format_args_nl", CFormatArgsNlExpander);

1 change: 1 addition & 0 deletions src/expand/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ ::std::unique_ptr<TokenStream> Expand_Macro_Inner(
return ProcMacro_Invoke(mi_span, crate, mac_path, input_tt);
}
TU_ARMA(BuiltinProcMacro, proc_mac) {
ASSERT_BUG(mi_span, proc_mac, "null BuiltinProcMacro? " << path);
auto e = input_ident == ""
? proc_mac->expand(mi_span, crate, input_tt, mod)
: proc_mac->expand_ident(mi_span, crate, input_ident, input_tt, mod)
Expand Down

0 comments on commit 1bc671d

Please sign in to comment.