From 1e873922f0d4fa08448d49c6f5333ffa67fe4704 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 17 Mar 2022 10:38:07 +0100 Subject: [PATCH] ast: Add Kind::MACRO_INVOCATION and cleanup fatal errors in lowering macro invocations --- gcc/rust/ast/rust-ast.h | 5 +++-- gcc/rust/ast/rust-macro.h | 2 ++ gcc/rust/hir/rust-ast-lower-expr.h | 8 -------- gcc/rust/hir/rust-ast-lower-implitem.h | 16 ---------------- gcc/rust/hir/rust-ast-lower-item.h | 8 -------- gcc/rust/hir/rust-ast-lower-stmt.h | 8 -------- gcc/rust/hir/rust-ast-lower.cc | 7 +++++++ 7 files changed, 12 insertions(+), 42 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 65871424ea3..4cb24109c9a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -41,6 +41,7 @@ enum Kind { UNKNOWN, MACRO_RULES_DEFINITION, + MACRO_INVOCATION, }; // Abstract base class for all AST elements @@ -900,7 +901,7 @@ protected: class ExprWithoutBlock; // Base expression AST node - abstract -class Expr +class Expr : public Node { public: // Unique pointer custom clone function @@ -1073,7 +1074,7 @@ protected: class TraitBound; // Base class for types as represented in AST - abstract -class Type +class Type : public Node { public: // Unique pointer custom clone function diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 4adf467ad48..1c5d1020b20 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -507,6 +507,8 @@ public: return ExprWithoutBlock::get_node_id (); } + Kind get_ast_kind () const override { return Kind::MACRO_INVOCATION; } + NodeId get_macro_node_id () const { return node_id; } MacroInvocData &get_invoc_data () { return invoc_data; } diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index e31686811f1..1915389948c 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -100,14 +100,6 @@ public: return resolver.translated; } - void visit (AST::MacroInvocation &expr) override - { - rust_fatal_error ( - expr.get_locus (), - "macro expansion failed: No macro invocation should get lowered to HIR " - "as they should disappear during expansion"); - } - void visit (AST::TupleIndexExpr &expr) override { HIR::Expr *tuple_expr diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 5d674ca168b..c9dfd1b6505 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -52,14 +52,6 @@ public: return resolver.translated; } - void visit (AST::MacroInvocation &invoc) override - { - rust_fatal_error ( - invoc.get_locus (), - "macro expansion failed: No macro invocation should get lowered to HIR " - "as they should disappear during expansion"); - } - void visit (AST::TypeAlias &alias) override { std::vector > where_clause_items; @@ -316,14 +308,6 @@ public: return resolver.translated; } - void visit (AST::MacroInvocation &invoc) override - { - rust_fatal_error ( - invoc.get_locus (), - "macro expansion failed: No macro invocation should get lowered to HIR " - "as they should disappear during expansion"); - } - void visit (AST::TraitItemFunc &func) override { AST::TraitFunctionDecl &ref = func.get_trait_function_decl (); diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 50ecf7bd523..376e6c2aabc 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -51,14 +51,6 @@ public: return resolver.translated; } - void visit (AST::MacroInvocation &invoc) override - { - rust_fatal_error ( - invoc.get_locus (), - "macro expansion failed: No macro invocation should get lowered to HIR " - "as they should disappear during expansion"); - } - void visit (AST::Module &module) override { auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index d0a1d382bb3..ede72bd71bf 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -45,14 +45,6 @@ public: return resolver.translated; } - void visit (AST::MacroInvocation &invoc) override - { - rust_fatal_error ( - invoc.get_locus (), - "macro expansion failed: No macro invocation should get lowered to HIR " - "as they should disappear during expansion"); - } - void visit (AST::ExprStmtWithBlock &stmt) override { HIR::ExprWithBlock *expr diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 27f73e02203..c373ae90a15 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -70,6 +70,13 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) 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 (), + "macro invocations should not get lowered to HIR - At " + "this point in " + "the pipeline, they should all have been expanded"); + if (block_did_terminate) rust_warning_at (s->get_locus (), 0, "unreachable statement");