aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-12-21 22:56:52 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:55:45 +0100
commit9c50565e333621a8f7715db38adda442b1fe8a00 (patch)
tree74c9cc71177eeeffb91b818c79b03123ff4b574e
parentc583545a9adaba0ab9d369f82b5f9bb1577e5f6e (diff)
downloadgcc-9c50565e333621a8f7715db38adda442b1fe8a00.zip
gcc-9c50565e333621a8f7715db38adda442b1fe8a00.tar.gz
gcc-9c50565e333621a8f7715db38adda442b1fe8a00.tar.bz2
gccrs: ast: Add new Kind enums for more precise downcasting
This commit adds things like Item::Kind, Expr::Kind, etc, and implements the associated `get_*_kind` functions. It also removes the more generic AST::Kind enum we were using, which was incomplete and painful to use. gcc/rust/ChangeLog: * ast/rust-ast.h: Add new Kind enums, remove Node class. * ast/rust-builtin-ast-nodes.h: Use new Kind enums. * ast/rust-expr.h (class LoopLabel): Likewise. * ast/rust-item.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.h: Likewise. * expand/rust-macro-builtins-helpers.cc: Likewise. * expand/rust-macro-builtins-utility.cc (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::stringify_handler): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-early-name-resolver.cc: Likewise. * hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Likewise.
-rw-r--r--gcc/rust/ast/rust-ast.h94
-rw-r--r--gcc/rust/ast/rust-builtin-ast-nodes.h2
-rw-r--r--gcc/rust/ast/rust-expr.h84
-rw-r--r--gcc/rust/ast/rust-item.h36
-rw-r--r--gcc/rust/ast/rust-macro.h34
-rw-r--r--gcc/rust/ast/rust-path.h10
-rw-r--r--gcc/rust/expand/rust-macro-builtins-helpers.cc2
-rw-r--r--gcc/rust/expand/rust-macro-builtins-utility.cc4
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.cc2
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver.cc10
11 files changed, 229 insertions, 55 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 42ad011..5e724d1 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -70,16 +70,6 @@ namespace AST {
class ASTVisitor;
using AttrVec = std::vector<Attribute>;
-// The available kinds of AST Nodes
-enum class Kind
-{
- UNKNOWN,
- MODULE,
- MACRO_RULES_DEFINITION,
- MACRO_INVOCATION,
- IDENTIFIER,
-};
-
class Visitable
{
public:
@@ -87,20 +77,6 @@ public:
virtual void accept_vis (ASTVisitor &vis) = 0;
};
-// Abstract base class for all AST elements
-class Node : public Visitable
-{
-public:
- /**
- * Get the kind of Node this is. This is used to differentiate various AST
- * elements with very little overhead when extracting the derived type
- * through static casting is not necessary.
- */
- // FIXME: Mark this as `= 0` in the future to make sure every node
- // implements it
- virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
-};
-
// Delimiter types - used in macros and whatever.
enum DelimType
{
@@ -1092,7 +1068,7 @@ class MetaListNameValueStr;
/* Base statement abstract class. Note that most "statements" are not allowed
* in top-level module scope - only a subclass of statements called "items"
* are. */
-class Stmt : public Node
+class Stmt : public Visitable
{
public:
enum class Kind
@@ -1141,6 +1117,28 @@ protected:
class Item : public Stmt
{
public:
+ enum class Kind
+ {
+ MacroRulesDefinition,
+ MacroInvocation,
+ Module,
+ ExternCrate,
+ UseDeclaration,
+ Function,
+ TypeAlias,
+ Struct,
+ EnumItem,
+ Enum,
+ Union,
+ ConstantItem,
+ StaticItem,
+ Trait,
+ Impl,
+ ExternBlock,
+ };
+
+ virtual Kind get_item_kind () const = 0;
+
// Unique pointer custom clone function
std::unique_ptr<Item> clone_item () const
{
@@ -1221,14 +1219,54 @@ public:
{
return outer_attrs;
}
+
+ virtual Item::Kind get_item_kind () const override = 0;
};
+
// forward decl of ExprWithoutBlock
class ExprWithoutBlock;
// Base expression AST node - abstract
-class Expr : public Node
+class Expr : public Visitable
{
public:
+ enum class Kind
+ {
+ PathInExpression,
+ QualifiedPathInExpression,
+ Literal,
+ Operator,
+ Grouped,
+ Array,
+ ArrayIndex,
+ Tuple,
+ TupleIndex,
+ Struct,
+ Call,
+ MethodCall,
+ FieldAccess,
+ Closure,
+ Block,
+ Continue,
+ Break,
+ Range,
+ Box,
+ Return,
+ UnsafeBlock,
+ Loop,
+ If,
+ IfLet,
+ Match,
+ Await,
+ AsyncBlock,
+ InlineAsm,
+ Identifier,
+ FormatArgs,
+ MacroInvocation,
+ };
+
+ virtual Kind get_expr_kind () const = 0;
+
// Unique pointer custom clone function
std::unique_ptr<Expr> clone_expr () const
{
@@ -1343,7 +1381,7 @@ public:
outer_attrs = std::move (new_attrs);
}
- Kind get_ast_kind () const override { return Kind::IDENTIFIER; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Identifier; }
protected:
// Clone method implementation
@@ -1410,7 +1448,7 @@ protected:
class TraitBound;
// Base class for types as represented in AST - abstract
-class Type : public Node
+class Type : public Visitable
{
public:
// Unique pointer custom clone function
diff --git a/gcc/rust/ast/rust-builtin-ast-nodes.h b/gcc/rust/ast/rust-builtin-ast-nodes.h
index 7ebd656..3684092 100644
--- a/gcc/rust/ast/rust-builtin-ast-nodes.h
+++ b/gcc/rust/ast/rust-builtin-ast-nodes.h
@@ -202,6 +202,8 @@ public:
const FormatArguments &get_arguments () const { return arguments; }
virtual location_t get_locus () const override;
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::FormatArgs; }
+
private:
location_t loc;
// FIXME: This probably needs to be a separate type - it is one in rustc's
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 483e599..852c3f3 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -15,7 +15,7 @@ namespace AST {
// Loop label expression AST node used with break and continue expressions
// TODO: inline?
-class LoopLabel /*: public Node*/
+class LoopLabel /*: public Visitable*/
{
Lifetime label; // or type LIFETIME_OR_LABEL
location_t locus;
@@ -117,6 +117,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Literal; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -365,6 +367,8 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Operator; }
};
/* Unary prefix & or &mut (or && and &&mut) borrow operator. Cannot be
@@ -1090,6 +1094,8 @@ public:
return expr_in_parens;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Grouped; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1319,6 +1325,8 @@ public:
return internal_elements;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Array; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1424,6 +1432,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::ArrayIndex; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1520,6 +1530,8 @@ public:
bool is_unit () const { return tuple_elems.size () == 0; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Tuple; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1607,6 +1619,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::TupleIndex; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1650,6 +1664,8 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Struct; }
};
// Actual AST node of the struct creator (with no fields). Not abstract!
@@ -2131,6 +2147,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Call; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2234,6 +2252,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::MethodCall; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2319,6 +2339,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::FieldAccess; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2454,6 +2476,8 @@ public:
}
bool get_has_move () const { return has_move; }
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Closure; }
};
// Represents a non-type-specified closure expression AST node
@@ -2675,6 +2699,8 @@ public:
bool has_label () { return !label.is_error (); }
LoopLabel &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Block; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2828,6 +2854,8 @@ public:
Lifetime &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Continue; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2924,6 +2952,8 @@ public:
LoopLabel &get_label () { return label; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Break; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2956,6 +2986,8 @@ public:
{
rust_assert (false);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Range; }
};
// Range from (inclusive) and to (exclusive) expression AST node object
@@ -3404,6 +3436,8 @@ public:
return *expr;
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Box; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3491,6 +3525,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Return; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3573,6 +3609,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::UnsafeBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3661,6 +3699,18 @@ public:
{
outer_attrs = std::move (new_attrs);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Loop; }
+
+ enum class Kind
+ {
+ Loop,
+ While,
+ WhileLet,
+ For
+ };
+
+ virtual Kind get_loop_kind () const = 0;
};
// 'Loop' expression (i.e. the infinite loop) AST node
@@ -3679,6 +3729,11 @@ public:
void accept_vis (ASTVisitor &vis) override;
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::Loop;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3737,6 +3792,11 @@ public:
return *condition;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::While;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3820,6 +3880,11 @@ public:
return match_arm_patterns;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::WhileLet;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3889,6 +3954,11 @@ public:
return *pattern;
}
+ BaseLoopExpr::Kind get_loop_kind () const override
+ {
+ return BaseLoopExpr::Kind::For;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4012,6 +4082,8 @@ public:
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::If; }
+
protected:
// Base clone function but still concrete as concrete base class
virtual IfExpr *clone_if_expr_impl () const { return new IfExpr (*this); }
@@ -4206,6 +4278,8 @@ public:
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::IfLet; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base (or rather this or any derived object) */
@@ -4535,6 +4609,8 @@ public:
const std::vector<MatchCase> &get_match_cases () const { return match_arms; }
std::vector<MatchCase> &get_match_cases () { return match_arms; }
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Match; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4614,6 +4690,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::Await; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4696,6 +4774,8 @@ public:
outer_attrs = std::move (new_attrs);
}
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::AsyncBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -5209,6 +5289,8 @@ public:
{
return new InlineAsm (*this);
}
+
+ Expr::Kind get_expr_kind () const override { return Expr::Kind::InlineAsm; }
};
} // namespace AST
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index ecd355f..0baefdc 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -758,8 +758,6 @@ public:
Identifier get_name () const { return module_name; }
- AST::Kind get_ast_kind () const override { return AST::Kind::MODULE; }
-
private:
Identifier module_name;
location_t locus;
@@ -899,6 +897,8 @@ public:
void mark_for_strip () override { module_name = {""}; }
bool is_marked_for_strip () const override { return module_name.empty (); }
+ Item::Kind get_item_kind () const override { return Item::Kind::Module; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -960,6 +960,8 @@ public:
return referenced_crate.empty ();
}
+ Item::Kind get_item_kind () const override { return Item::Kind::ExternCrate; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1301,6 +1303,11 @@ public:
void mark_for_strip () override { use_tree = nullptr; }
bool is_marked_for_strip () const override { return use_tree == nullptr; }
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::UseDeclaration;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1459,6 +1466,8 @@ public:
// ExternalItem::node_id is same as Stmt::node_id
NodeId get_node_id () const override { return Stmt::node_id; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Function; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1590,6 +1599,8 @@ public:
Identifier get_new_type_name () const { return new_type_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::TypeAlias; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1649,6 +1660,8 @@ public:
Identifier get_identifier () const { return struct_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Struct; }
+
protected:
Struct (Identifier struct_name,
std::vector<std::unique_ptr<GenericParam>> generic_params,
@@ -2058,6 +2071,8 @@ public:
void mark_for_strip () override { variant_name = {""}; }
bool is_marked_for_strip () const override { return variant_name.empty (); }
+ Item::Kind get_item_kind () const override { return Item::Kind::EnumItem; }
+
protected:
EnumItem *clone_item_impl () const override { return new EnumItem (*this); }
};
@@ -2321,6 +2336,8 @@ public:
// TODO: is this better? Or is a "vis_block" better?
WhereClause &get_where_clause () { return where_clause; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Enum; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2420,6 +2437,8 @@ public:
Identifier get_identifier () const { return union_name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Union; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2541,6 +2560,11 @@ public:
std::string get_identifier () const { return identifier; }
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::ConstantItem;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2662,6 +2686,8 @@ public:
Identifier get_identifier () const { return name; }
+ Item::Kind get_item_kind () const override { return Item::Kind::StaticItem; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -3025,6 +3051,8 @@ public:
AST::TypeParam &get_implicit_self () { return self_param; }
+ Item::Kind get_item_kind () const override { return Item::Kind::Trait; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -3097,6 +3125,8 @@ public:
return trait_type;
}
+ Item::Kind get_item_kind () const override { return Item::Kind::Impl; }
+
protected:
// Mega-constructor
Impl (std::vector<std::unique_ptr<GenericParam>> generic_params,
@@ -3982,6 +4012,8 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ Item::Kind get_item_kind () const override { return Item::Kind::ExternBlock; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index a953b75..fc01e57 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -28,6 +28,7 @@
namespace Rust {
namespace AST {
+
class MacroFragSpec
{
public:
@@ -571,13 +572,13 @@ public:
is_builtin_rule = true;
}
- AST::Kind get_ast_kind () const override
+ MacroKind get_kind () const { return kind; }
+
+ Item::Kind get_item_kind () const override
{
- return AST::Kind::MACRO_RULES_DEFINITION;
+ return Item::Kind::MacroRulesDefinition;
}
- MacroKind get_kind () const { return kind; }
-
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -609,11 +610,6 @@ public:
std::string as_string () const override;
- Pattern::Kind get_pattern_kind () override
- {
- return Pattern::Kind::MacroInvocation;
- }
-
/**
* The default constructor you should use. Whenever we parse a macro call, we
* cannot possibly know whether or not this call refers to a builtin macro or
@@ -676,11 +672,6 @@ public:
return ExprWithoutBlock::get_node_id ();
}
- AST::Kind get_ast_kind () const override
- {
- return AST::Kind::MACRO_INVOCATION;
- }
-
NodeId get_macro_node_id () const { return node_id; }
MacroInvocData &get_invoc_data () { return invoc_data; }
@@ -799,6 +790,21 @@ public:
void add_semicolon () override { is_semi_coloned = true; }
+ Pattern::Kind get_pattern_kind () override
+ {
+ return Pattern::Kind::MacroInvocation;
+ }
+
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::MacroInvocation;
+ }
+
+ Item::Kind get_item_kind () const override
+ {
+ return Item::Kind::MacroInvocation;
+ }
+
protected:
Item *clone_item_impl () const override
{
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 4e26b2f..b7eba44 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -850,6 +850,11 @@ public:
Pattern::Kind get_pattern_kind () override { return Pattern::Kind::Path; }
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::PathInExpression;
+ }
+
protected:
PathInExpression (std::vector<Attribute> &&outer_attrs,
bool has_opening_scope_resolution, location_t locus,
@@ -1516,6 +1521,11 @@ public:
rust_unreachable ();
}
+ Expr::Kind get_expr_kind () const override
+ {
+ return Expr::Kind::QualifiedPathInExpression;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/expand/rust-macro-builtins-helpers.cc b/gcc/rust/expand/rust-macro-builtins-helpers.cc
index 55d113c..864379a 100644
--- a/gcc/rust/expand/rust-macro-builtins-helpers.cc
+++ b/gcc/rust/expand/rust-macro-builtins-helpers.cc
@@ -36,7 +36,7 @@ check_for_eager_invocations (
std::vector<std::unique_ptr<AST::MacroInvocation>> pending;
for (auto &expr : expressions)
- if (expr->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
+ if (expr->get_expr_kind () == AST::Expr::Kind::MacroInvocation)
pending.emplace_back (std::unique_ptr<AST::MacroInvocation> (
static_cast<AST::MacroInvocation *> (expr->clone_expr ().release ())));
diff --git a/gcc/rust/expand/rust-macro-builtins-utility.cc b/gcc/rust/expand/rust-macro-builtins-utility.cc
index 2da7d18..9ea854e 100644
--- a/gcc/rust/expand/rust-macro-builtins-utility.cc
+++ b/gcc/rust/expand/rust-macro-builtins-utility.cc
@@ -117,7 +117,7 @@ MacroBuiltin::concat_handler (location_t invoc_locus,
for (auto &expr : expanded_expr)
{
if (!expr->is_literal ()
- && expr->get_ast_kind () != AST::Kind::MACRO_INVOCATION)
+ && expr->get_expr_kind () != AST::Expr::Kind::MacroInvocation)
{
has_error = true;
rust_error_at (expr->get_locus (), "expected a literal");
@@ -296,4 +296,4 @@ MacroBuiltin::stringify_handler (location_t invoc_locus,
return AST::Fragment ({node}, std::move (token));
}
-} // namespace Rust \ No newline at end of file
+} // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index c5e2250..a94a843 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -104,7 +104,11 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
for (auto &s : expr.get_statements ())
{
- if (s->get_ast_kind () == AST::Kind::MACRO_INVOCATION)
+ // FIXME: We basically need to do that check for *every* single node in
+ // the AST. this isn't realistic and this should be turned into an
+ // optional, debug-visitor instead, which goes through the entire AST and
+ // checks if any of the nodes are macro invocations
+ if (s->get_stmt_kind () == AST::Stmt::Kind::MacroInvocation)
rust_fatal_error (
s->get_locus (),
"macro invocations should not get lowered to HIR - At "
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 7ddf4a9..6524376 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -537,7 +537,7 @@ ResolveExpr::visit (AST::BreakExpr &expr)
{
bool funny_error = false;
auto &break_expr = expr.get_break_expr ();
- if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER)
+ if (break_expr.get_expr_kind () == AST::Expr::Kind::Identifier)
{
/* This is a break with an expression, and the expression is
just a single identifier. See if the identifier is either
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index a46b57f..34bac98 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -17,7 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-early-name-resolver.h"
-#include "rust-ast-full.h"
+#include "rust-pattern.h"
#include "rust-name-resolver.h"
#include "rust-macro-builtins.h"
#include "rust-attribute-values.h"
@@ -53,7 +53,7 @@ EarlyNameResolver::accumulate_escaped_macros (AST::Module &module)
scoped (module.get_node_id (), [&module, &escaped_macros, this] {
for (auto &item : module.get_items ())
{
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
{
auto &module = *static_cast<AST::Module *> (item.get ());
auto new_macros = accumulate_escaped_macros (module);
@@ -64,7 +64,7 @@ EarlyNameResolver::accumulate_escaped_macros (AST::Module &module)
continue;
}
- if (item->get_ast_kind () == AST::Kind::MACRO_RULES_DEFINITION)
+ if (item->get_item_kind () == AST::Item::Kind::MacroRulesDefinition)
escaped_macros.emplace_back (item->clone_item ());
}
});
@@ -113,7 +113,7 @@ EarlyNameResolver::visit (AST::Crate &crate)
{
auto new_macros = std::vector<std::unique_ptr<AST::Item>> ();
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
new_macros = accumulate_escaped_macros (
*static_cast<AST::Module *> (item.get ()));
@@ -300,7 +300,7 @@ EarlyNameResolver::visit (AST::Module &module)
{
auto new_macros = std::vector<std::unique_ptr<AST::Item>> ();
- if (item->get_ast_kind () == AST::Kind::MODULE)
+ if (item->get_item_kind () == AST::Item::Kind::Module)
new_macros = accumulate_escaped_macros (
*static_cast<AST::Module *> (item.get ()));