ast: Add Kind::MACRO_INVOCATION and cleanup fatal errors in lowering

macro invocations
This commit is contained in:
Arthur Cohen 2022-03-17 10:38:07 +01:00
parent b776c4953c
commit 1e873922f0
7 changed files with 12 additions and 42 deletions

View File

@ -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

View File

@ -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; }

View File

@ -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

View File

@ -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<std::unique_ptr<HIR::WhereClauseItem> > 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 ();

View File

@ -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 ();

View File

@ -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

View File

@ -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");