From 26d3103c2d65741221920a0239d9f02ac5e61e6d Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Sat, 21 Dec 2024 22:56:52 +0000 Subject: [PATCH] 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. --- gcc/rust/ast/rust-ast.h | 94 +++++++++++++------ gcc/rust/ast/rust-builtin-ast-nodes.h | 2 + gcc/rust/ast/rust-expr.h | 84 ++++++++++++++++- gcc/rust/ast/rust-item.h | 36 ++++++- gcc/rust/ast/rust-macro.h | 34 ++++--- gcc/rust/ast/rust-path.h | 10 ++ .../expand/rust-macro-builtins-helpers.cc | 2 +- .../expand/rust-macro-builtins-utility.cc | 4 +- gcc/rust/hir/rust-ast-lower.cc | 6 +- gcc/rust/resolve/rust-ast-resolve-expr.cc | 2 +- gcc/rust/resolve/rust-early-name-resolver.cc | 10 +- 11 files changed, 229 insertions(+), 55 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index f83c99a57d2d..2d907e2ca21a 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; -// The available kinds of AST Nodes -enum class Kind -{ - UNKNOWN, - MODULE, - MACRO_RULES_DEFINITION, - MACRO_INVOCATION, - IDENTIFIER, -}; - class Visitable { public: @@ -87,20 +77,6 @@ class Visitable 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 @@ class Stmt : public Node 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 clone_item () const { @@ -1221,14 +1219,54 @@ class VisItem : public Item { 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 clone_expr () const { @@ -1343,7 +1381,7 @@ class IdentifierExpr : public ExprWithoutBlock 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 @@ class Pattern : public Visitable 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 3e21d7e718d6..df3db85888d8 100644 --- a/gcc/rust/ast/rust-builtin-ast-nodes.h +++ b/gcc/rust/ast/rust-builtin-ast-nodes.h @@ -202,6 +202,8 @@ class FormatArgs : public Expr 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 483e599652bb..852c3f3a3a45 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 @@ class LiteralExpr : public ExprWithoutBlock 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 @@ class OperatorExpr : public ExprWithoutBlock { 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 @@ class GroupedExpr : public ExprWithoutBlock 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 @@ class ArrayExpr : public ExprWithoutBlock 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 @@ class ArrayIndexExpr : public ExprWithoutBlock 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 @@ class TupleExpr : public ExprWithoutBlock 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 @@ class TupleIndexExpr : public ExprWithoutBlock 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 @@ class StructExpr : public ExprWithoutBlock { 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 @@ class CallExpr : public ExprWithoutBlock 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 @@ class MethodCallExpr : public ExprWithoutBlock 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 @@ class FieldAccessExpr : public ExprWithoutBlock 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 @@ class ClosureExpr : public ExprWithoutBlock } 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 @@ class BlockExpr : public ExprWithBlock 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 @@ class ContinueExpr : public ExprWithoutBlock 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 @@ class BreakExpr : public ExprWithoutBlock 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 @@ class RangeExpr : public ExprWithoutBlock { 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 @@ class BoxExpr : public ExprWithoutBlock 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 @@ class ReturnExpr : public ExprWithoutBlock 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 @@ class UnsafeBlockExpr : public ExprWithBlock 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 @@ class BaseLoopExpr : public ExprWithBlock { 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 @@ class LoopExpr : public BaseLoopExpr 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 @@ class WhileLoopExpr : public BaseLoopExpr 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 @@ class WhileLetLoopExpr : public BaseLoopExpr 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 @@ class ForLoopExpr : public BaseLoopExpr 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 @@ class IfExpr : public ExprWithBlock const std::vector &get_outer_attrs () const { return outer_attrs; } std::vector &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 @@ class IfLetExpr : public ExprWithBlock const std::vector &get_outer_attrs () const { return outer_attrs; } std::vector &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 @@ class MatchExpr : public ExprWithBlock const std::vector &get_match_cases () const { return match_arms; } std::vector &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 @@ class AwaitExpr : public ExprWithoutBlock 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 @@ class AsyncBlockExpr : public ExprWithBlock 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 @@ class InlineAsm : public ExprWithoutBlock { 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 a380081a0421..6c9789d5999b 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -758,8 +758,6 @@ class Module : public VisItem 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 @@ class Module : public VisItem 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 @@ class ExternCrate : public VisItem 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 @@ class UseDeclaration : public VisItem 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 @@ class Function : public VisItem, public AssociatedItem, public ExternalItem // 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 @@ class TypeAlias : public VisItem, public AssociatedItem 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 @@ class Struct : public VisItem 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> generic_params, @@ -2058,6 +2071,8 @@ class EnumItem : public VisItem 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 @@ class Enum : public VisItem // 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 @@ class Union : public VisItem 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 @@ class ConstantItem : public VisItem, public AssociatedItem 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 @@ class StaticItem : public VisItem 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 @@ class Trait : public VisItem 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 @@ class Impl : public VisItem return trait_type; } + Item::Kind get_item_kind () const override { return Item::Kind::Impl; } + protected: // Mega-constructor Impl (std::vector> generic_params, @@ -3982,6 +4012,8 @@ class ExternBlock : public VisItem const std::vector &get_inner_attrs () const { return inner_attrs; } std::vector &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 07a571561ba5..575cd231af79 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 @@ class MacroRulesDefinition : public VisItem 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 @@ class MacroInvocation : public TypeNoBounds, 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 @@ class MacroInvocation : public TypeNoBounds, 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 @@ class MacroInvocation : public TypeNoBounds, 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 f8e0c1cfd6ae..ae40a7eb94b9 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -850,6 +850,11 @@ class PathInExpression : public Pattern, public ExprWithoutBlock 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 &&outer_attrs, bool has_opening_scope_resolution, location_t locus, @@ -1516,6 +1521,11 @@ class QualifiedPathInExpression : public Pattern, public ExprWithoutBlock 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 686edde23f23..33fe93f68a69 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> 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 ( static_cast (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 aea2902202bb..ff64879c5eae 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 c92c9432a68e..e33f5794a621 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 9c2be4a57160..5936cf2c31ef 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -536,7 +536,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 634523181139..2fe01b67f557 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -17,7 +17,7 @@ // . #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 (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> (); - if (item->get_ast_kind () == AST::Kind::MODULE) + if (item->get_item_kind () == AST::Item::Kind::Module) new_macros = accumulate_escaped_macros ( *static_cast (item.get ())); @@ -300,7 +300,7 @@ EarlyNameResolver::visit (AST::Module &module) { auto new_macros = std::vector> (); - if (item->get_ast_kind () == AST::Kind::MODULE) + if (item->get_item_kind () == AST::Item::Kind::Module) new_macros = accumulate_escaped_macros ( *static_cast (item.get ()));