Skip to content

Commit 1e87392

Browse files
committed
ast: Add Kind::MACRO_INVOCATION and cleanup fatal errors in lowering
macro invocations
1 parent b776c49 commit 1e87392

7 files changed

+12
-42
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum Kind
4141
{
4242
UNKNOWN,
4343
MACRO_RULES_DEFINITION,
44+
MACRO_INVOCATION,
4445
};
4546

4647
// Abstract base class for all AST elements
@@ -900,7 +901,7 @@ class Item : public Stmt
900901
class ExprWithoutBlock;
901902

902903
// Base expression AST node - abstract
903-
class Expr
904+
class Expr : public Node
904905
{
905906
public:
906907
// Unique pointer custom clone function
@@ -1073,7 +1074,7 @@ class Pattern
10731074
class TraitBound;
10741075

10751076
// Base class for types as represented in AST - abstract
1076-
class Type
1077+
class Type : public Node
10771078
{
10781079
public:
10791080
// Unique pointer custom clone function

gcc/rust/ast/rust-macro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ class MacroInvocation : public TypeNoBounds,
507507
return ExprWithoutBlock::get_node_id ();
508508
}
509509

510+
Kind get_ast_kind () const override { return Kind::MACRO_INVOCATION; }
511+
510512
NodeId get_macro_node_id () const { return node_id; }
511513

512514
MacroInvocData &get_invoc_data () { return invoc_data; }

gcc/rust/hir/rust-ast-lower-expr.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ class ASTLoweringExpr : public ASTLoweringBase
100100
return resolver.translated;
101101
}
102102

103-
void visit (AST::MacroInvocation &expr) override
104-
{
105-
rust_fatal_error (
106-
expr.get_locus (),
107-
"macro expansion failed: No macro invocation should get lowered to HIR "
108-
"as they should disappear during expansion");
109-
}
110-
111103
void visit (AST::TupleIndexExpr &expr) override
112104
{
113105
HIR::Expr *tuple_expr

gcc/rust/hir/rust-ast-lower-implitem.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ class ASTLowerImplItem : public ASTLoweringBase
5252
return resolver.translated;
5353
}
5454

55-
void visit (AST::MacroInvocation &invoc) override
56-
{
57-
rust_fatal_error (
58-
invoc.get_locus (),
59-
"macro expansion failed: No macro invocation should get lowered to HIR "
60-
"as they should disappear during expansion");
61-
}
62-
6355
void visit (AST::TypeAlias &alias) override
6456
{
6557
std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
@@ -316,14 +308,6 @@ class ASTLowerTraitItem : public ASTLoweringBase
316308
return resolver.translated;
317309
}
318310

319-
void visit (AST::MacroInvocation &invoc) override
320-
{
321-
rust_fatal_error (
322-
invoc.get_locus (),
323-
"macro expansion failed: No macro invocation should get lowered to HIR "
324-
"as they should disappear during expansion");
325-
}
326-
327311
void visit (AST::TraitItemFunc &func) override
328312
{
329313
AST::TraitFunctionDecl &ref = func.get_trait_function_decl ();

gcc/rust/hir/rust-ast-lower-item.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ class ASTLoweringItem : public ASTLoweringBase
5151
return resolver.translated;
5252
}
5353

54-
void visit (AST::MacroInvocation &invoc) override
55-
{
56-
rust_fatal_error (
57-
invoc.get_locus (),
58-
"macro expansion failed: No macro invocation should get lowered to HIR "
59-
"as they should disappear during expansion");
60-
}
61-
6254
void visit (AST::Module &module) override
6355
{
6456
auto crate_num = mappings->get_current_crate ();

gcc/rust/hir/rust-ast-lower-stmt.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ class ASTLoweringStmt : public ASTLoweringBase
4545
return resolver.translated;
4646
}
4747

48-
void visit (AST::MacroInvocation &invoc) override
49-
{
50-
rust_fatal_error (
51-
invoc.get_locus (),
52-
"macro expansion failed: No macro invocation should get lowered to HIR "
53-
"as they should disappear during expansion");
54-
}
55-
5648
void visit (AST::ExprStmtWithBlock &stmt) override
5749
{
5850
HIR::ExprWithBlock *expr

gcc/rust/hir/rust-ast-lower.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
7070
if (s->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION)
7171
continue;
7272

73+
if (s->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
74+
rust_fatal_error (
75+
s->get_locus (),
76+
"macro invocations should not get lowered to HIR - At "
77+
"this point in "
78+
"the pipeline, they should all have been expanded");
79+
7380
if (block_did_terminate)
7481
rust_warning_at (s->get_locus (), 0, "unreachable statement");
7582

0 commit comments

Comments
 (0)