aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-builtins-asm.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-06-18 13:47:57 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:49 +0100
commit92418978e8a82f6ed86a86caf6fa37b4598a019e (patch)
tree0f0c20aea1d04b42006165b7db8583df71f561be /gcc/rust/expand/rust-macro-builtins-asm.cc
parentd129c4ed8045f2e5f53b5cdddfd4caec1aa9d8e9 (diff)
downloadgcc-92418978e8a82f6ed86a86caf6fa37b4598a019e.zip
gcc-92418978e8a82f6ed86a86caf6fa37b4598a019e.tar.gz
gcc-92418978e8a82f6ed86a86caf6fa37b4598a019e.tar.bz2
gccrs: expand: Switch semicolon boolean to an enum instead.
gcc/rust/ChangeLog: * ast/rust-ast-fragment.h (enum class): Add InvocKind and AsmKind enums. * ast/rust-macro.h: Switch semicolon boolean to InvocKind enum. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-macro-builtins-asm.cc (MacroBuiltin::asm_handler): Likewise. (parse_asm): Likewise. * expand/rust-macro-builtins-asm.h (parse_asm): Likewise. * expand/rust-macro-builtins-format-args.cc (MacroBuiltin::format_args_handler): Likewise. * expand/rust-macro-builtins-include.cc (MacroBuiltin::include_bytes_handler): Likewise. (MacroBuiltin::include_str_handler): Likewise. (MacroBuiltin::include_handler): Likewise. * expand/rust-macro-builtins-location.cc (MacroBuiltin::file_handler): Likewise. (MacroBuiltin::column_handler): Likewise. (MacroBuiltin::line_handler): Likewise. * expand/rust-macro-builtins-log-debug.cc (MacroBuiltin::assert_handler): Likewise. * expand/rust-macro-builtins-utility.cc (MacroBuiltin::compile_error_handler): Likewise. (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::env_handler): Likewise. (MacroBuiltin::cfg_handler): Likewise. (MacroBuiltin::stringify_handler): Likewise. * expand/rust-macro-builtins.cc (format_args_maker): Likewise. (enum class): Likewise. (inline_asm_maker): Likewise. (MacroBuiltin::sorry): Likewise. (MacroBuiltin::proc_macro_builtin): Likewise. * expand/rust-macro-builtins.h: Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise. (MacroExpander::expand_eager_invocations): Likewise. (MacroExpander::expand_invoc): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise.
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins-asm.cc')
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 3145769..5b4661a 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -16,7 +16,9 @@
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include "rust-make-unique.h"
#include "rust-macro-builtins-asm.h"
+#include "rust-ast-fragment.h"
#include "rust-ast.h"
#include "rust-stmt.h"
@@ -537,9 +539,9 @@ parse_format_string (InlineAsmContext &inline_asm_ctx)
tl::optional<AST::Fragment>
MacroBuiltin::asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
- bool semicolon, bool is_global_asm)
+ AST::InvocKind semicolon, AST::AsmKind is_global_asm)
{
- return parse_asm (invoc_locus, invoc, is_global_asm, semicolon);
+ return parse_asm (invoc_locus, invoc, semicolon, is_global_asm);
}
tl::expected<InlineAsmContext, std::string>
@@ -609,7 +611,7 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
tl::optional<AST::Fragment>
parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
- bool is_global_asm, bool semicolon)
+ AST::InvocKind semicolon, AST::AsmKind is_global_asm)
{
// From the rule of asm.
// We first peek and see if it is a format string or not.
@@ -631,7 +633,8 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
Parser<MacroInvocLexer> parser (lex);
auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser);
- AST::InlineAsm inline_asm (invoc_locus, is_global_asm);
+ AST::InlineAsm inline_asm (invoc_locus,
+ is_global_asm == AST::AsmKind::Global);
auto inline_asm_ctx = InlineAsmContext (inline_asm, parser, last_token_id);
// operands stream, also handles the optional ","
@@ -654,10 +657,11 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
// If the macro invocation has a semicolon (`asm!("...");`), then we need
// to make it a statement. This way, it will be expanded properly.
- if (semicolon)
- single_vec.emplace_back (
- AST::SingleASTNode (std::unique_ptr<AST::Stmt> (
- new AST::ExprStmt (std::move (node), invoc_locus, semicolon))));
+ if (semicolon == AST::InvocKind::Semicoloned)
+ single_vec.emplace_back (AST::SingleASTNode (
+ Rust::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
+ semicolon
+ == AST::InvocKind::Semicoloned)));
else
single_vec.emplace_back (AST::SingleASTNode (std::move (node)));