diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-03-02 14:41:54 +0100 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-03-25 08:47:34 +0000 |
commit | 2b52571e8aa28a100b8989ece12e929a9fb6bcf4 (patch) | |
tree | efb9e0e3262ada92e75fce9b1fd3b1c284572643 /gcc/rust/hir/rust-ast-lower.cc | |
parent | a3e7bde5b0ab530b10483818d52504f7942ecdd5 (diff) | |
download | gcc-2b52571e8aa28a100b8989ece12e929a9fb6bcf4.zip gcc-2b52571e8aa28a100b8989ece12e929a9fb6bcf4.tar.gz gcc-2b52571e8aa28a100b8989ece12e929a9fb6bcf4.tar.bz2 |
lowering: Add lowering of exported macros
Macros marked with #[macro_export] need to be lowered to HIR in order
to get exported to the relevant metadata files.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_macro_definition):
New function.
* hir/rust-ast-lower-base.h: Declare `lower_macro_definition`.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Lower public
macro definitions.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
* hir/rust-ast-lower-stmt.h: Add visitor for `AST::MacroRulesDefinition`.
* hir/rust-ast-lower.cc (ASTLowering::go): Formatting.
(ASTLoweringBlock::visit): Visit `AST::MacroRulesDefinition`
(ASTLoweringIfLetBlock::visit): Formatting.
(ASTLoweringExprWithBlock::visit): Formatting.
Diffstat (limited to 'gcc/rust/hir/rust-ast-lower.cc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index c2fd54d..9b6227c 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -72,7 +72,7 @@ ASTLowering::Resolve (AST::Crate &astCrate) std::unique_ptr<HIR::Crate> ASTLowering::go () { - std::vector<std::unique_ptr<HIR::Item> > items; + std::vector<std::unique_ptr<HIR::Item>> items; for (auto it = astCrate.items.begin (); it != astCrate.items.end (); it++) { @@ -95,14 +95,11 @@ ASTLowering::go () void ASTLoweringBlock::visit (AST::BlockExpr &expr) { - std::vector<std::unique_ptr<HIR::Stmt> > block_stmts; + std::vector<std::unique_ptr<HIR::Stmt>> block_stmts; bool block_did_terminate = false; for (auto &s : expr.get_statements ()) { - if (s->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION) - continue; - if (s->get_ast_kind () == AST::Kind::MACRO_INVOCATION) rust_fatal_error ( s->get_locus (), @@ -115,8 +112,10 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) bool terminated = false; auto translated_stmt = ASTLoweringStmt::translate (s.get (), &terminated); - block_stmts.push_back (std::unique_ptr<HIR::Stmt> (translated_stmt)); block_did_terminate |= terminated; + + if (translated_stmt) + block_stmts.push_back (std::unique_ptr<HIR::Stmt> (translated_stmt)); } if (expr.has_tail_expr () && block_did_terminate) @@ -230,7 +229,7 @@ ASTLoweringIfBlock::visit (AST::IfExprConseqIf &expr) void ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr) { - std::vector<std::unique_ptr<HIR::Pattern> > patterns; + std::vector<std::unique_ptr<HIR::Pattern>> patterns; for (auto &pattern : expr.get_patterns ()) { HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ()); @@ -372,7 +371,7 @@ ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr) match_case.get_arm ().get_guard_expr ().get ()); } - std::vector<std::unique_ptr<HIR::Pattern> > match_arm_patterns; + std::vector<std::unique_ptr<HIR::Pattern>> match_arm_patterns; for (auto &pattern : match_case.get_arm ().get_patterns ()) { HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ()); |