From 0ca4ff41e5932ce5bf66c8e2aa8980dec4019af2 Mon Sep 17 00:00:00 2001 From: Om Swaroop Nayak <96killerat96@gmail.com> Date: Mon, 6 Jan 2025 12:28:36 -0800 Subject: [PATCH 1/4] gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit):removed fn * ast/rust-ast-collector.h: "removed defn" * ast/rust-ast-full-decls.h (class EnumItemDiscriminant):remove fn * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):removed fn * ast/rust-ast-visitor.h:"removed defn" * ast/rust-ast.cc (EnumItemDiscriminant::as_string):removed fn (EnumItemDiscriminant::accept_vis):removed fn (FormatArgs::set_outer_attrs): removed fn * ast/rust-item.h (class EnumItem): "added Discriminant expr" (class EnumItemDiscriminant): "removed redundant class" * expand/rust-cfg-strip.cc (CfgStrip::visit):removed fn * expand/rust-cfg-strip.h:"removed defn" * expand/rust-derive.h:"removed defn" * expand/rust-expand-visitor.cc (ExpandVisitor::visit):removed fn * expand/rust-expand-visitor.h:"removed defn" * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):removed fn * hir/rust-ast-lower-base.h:removed defn * hir/rust-ast-lower-enumitem.h:removed defn * parse/rust-parse-impl.h (Parser::parse_enum_item):"modified fn" (Parser::parse_pattern): modified fn * resolve/rust-ast-resolve-base.cc (ResolverBase::visit):removed fn * resolve/rust-ast-resolve-base.h:"removed defn" * resolve/rust-ast-resolve-item.cc (ResolveItem::visit):removed fn * resolve/rust-ast-resolve-item.h:"removed defn" * resolve/rust-ast-resolve-stmt.h:"removed defn" * resolve/rust-ast-resolve-toplevel.h:"removed defn" * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): "fn" * resolve/rust-toplevel-name-resolver-2.0.h:"removed defn" * util/rust-attributes.cc (AttributeChecker::visit):removed fn * util/rust-attributes.h:"removed defn" Signed-off-by: Om Swaroop Nayak <96killerat96@gmail.com> --- gcc/rust/ast/rust-ast-collector.cc | 9 -- gcc/rust/ast/rust-ast-collector.h | 1 - gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast-visitor.cc | 7 -- gcc/rust/ast/rust-ast-visitor.h | 2 - gcc/rust/ast/rust-ast.cc | 21 +--- gcc/rust/ast/rust-item.h | 96 ++++++------------- gcc/rust/expand/rust-cfg-strip.cc | 21 ---- gcc/rust/expand/rust-cfg-strip.h | 1 - gcc/rust/expand/rust-derive.h | 1 - gcc/rust/expand/rust-expand-visitor.cc | 6 -- gcc/rust/expand/rust-expand-visitor.h | 1 - gcc/rust/hir/rust-ast-lower-base.cc | 3 - gcc/rust/hir/rust-ast-lower-base.h | 1 - gcc/rust/hir/rust-ast-lower-enumitem.h | 20 ---- gcc/rust/parse/rust-parse-impl.h | 10 +- gcc/rust/resolve/rust-ast-resolve-base.cc | 4 - gcc/rust/resolve/rust-ast-resolve-base.h | 1 - gcc/rust/resolve/rust-ast-resolve-item.cc | 11 --- gcc/rust/resolve/rust-ast-resolve-item.h | 1 - gcc/rust/resolve/rust-ast-resolve-stmt.h | 20 ---- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 22 ----- .../rust-toplevel-name-resolver-2.0.cc | 6 -- .../resolve/rust-toplevel-name-resolver-2.0.h | 1 - gcc/rust/util/rust-attributes.cc | 4 - gcc/rust/util/rust-attributes.h | 1 - 26 files changed, 35 insertions(+), 237 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 8f66742d1196..ff6c12e147ad 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -1881,15 +1881,6 @@ TokenCollector::visit (EnumItemStruct &item) {Rust::Token::make (COMMA, UNDEF_LOCATION)}); } -void -TokenCollector::visit (EnumItemDiscriminant &item) -{ - auto id = item.get_identifier ().as_string (); - push (Rust::Token::make_identifier (item.get_locus (), std::move (id))); - push (Rust::Token::make (EQUAL, UNDEF_LOCATION)); - visit (item.get_expr ()); -} - void TokenCollector::visit (Enum &enumeration) { diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h index ceb161ccc139..69004d619cda 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -323,7 +323,6 @@ class TokenCollector : public ASTVisitor void visit (EnumItem &item); void visit (EnumItemTuple &item); void visit (EnumItemStruct &item); - void visit (EnumItemDiscriminant &item); void visit (Enum &enumeration); void visit (Union &union_item); void visit (ConstantItem &const_item); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index fffeb1b34660..e235758d4b18 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -188,7 +188,6 @@ class TupleStruct; class EnumItem; class EnumItemTuple; class EnumItemStruct; -class EnumItemDiscriminant; class Enum; class Union; class ConstantItem; diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 7c5117d48dbb..c751c0ac2ac6 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -920,13 +920,6 @@ DefaultASTVisitor::visit (AST::EnumItemStruct &item) visit (field); } -void -DefaultASTVisitor::visit (AST::EnumItemDiscriminant &item) -{ - visit (reinterpret_cast (item)); - visit (item.get_expr ()); -} - void DefaultASTVisitor::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 42513fe22d3c..9b85389c269f 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -157,7 +157,6 @@ class ASTVisitor virtual void visit (EnumItem &item) = 0; virtual void visit (EnumItemTuple &item) = 0; virtual void visit (EnumItemStruct &item) = 0; - virtual void visit (EnumItemDiscriminant &item) = 0; virtual void visit (Enum &enum_item) = 0; virtual void visit (Union &union_item) = 0; virtual void visit (ConstantItem &const_item) = 0; @@ -335,7 +334,6 @@ class DefaultASTVisitor : public ASTVisitor virtual void visit (AST::EnumItem &item) override; virtual void visit (AST::EnumItemTuple &item) override; virtual void visit (AST::EnumItemStruct &item) override; - virtual void visit (AST::EnumItemDiscriminant &item) override; virtual void visit (AST::Enum &enum_item) override; virtual void visit (AST::Union &union_item) override; virtual void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index f32f0caa3176..760ac0fb8465 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2952,18 +2952,6 @@ StructField::as_string () const return str; } -std::string -EnumItemDiscriminant::as_string () const -{ - // TODO: rewrite to work with non-linearisable exprs - std::string str = EnumItem::as_string (); - - // add equal and expression - str += " = " + expression->as_string (); - - return str; -} - std::string ExternalTypeItem::as_string () const { @@ -4765,12 +4753,6 @@ EnumItemStruct::accept_vis (ASTVisitor &vis) vis.visit (*this); } -void -EnumItemDiscriminant::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - void Enum::accept_vis (ASTVisitor &vis) { @@ -5060,7 +5042,8 @@ FormatArgs::get_outer_attrs () rust_unreachable (); } -void FormatArgs::set_outer_attrs (std::vector) +void +FormatArgs::set_outer_attrs (std::vector) { rust_unreachable (); } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 6c9789d5999b..037b889479c7 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2006,6 +2006,8 @@ class EnumItem : public VisItem location_t locus; + std::unique_ptr expression; + public: enum class Kind { @@ -2039,7 +2041,6 @@ class EnumItem : public VisItem // // gccrs#3340 - Discriminant, }; virtual ~EnumItem () {} @@ -2050,6 +2051,19 @@ class EnumItem : public VisItem variant_name (std::move (variant_name)), locus (locus) {} + EnumItem (Identifier variant_name, Visibility vis, + std::vector outer_attrs, location_t locus, + std::unique_ptr Discriminant) + : VisItem (std::move (vis), std::move (outer_attrs)), + variant_name (std::move (variant_name)), locus (locus), + expression (Discriminant->clone_expr ()) + {} + + EnumItem (EnumItem const &other) + : VisItem (other), variant_name (other.variant_name), locus (other.locus), + expression (other.expression->clone_expr ()) + {} + virtual Kind get_enum_item_kind () const { return Kind::Identifier; } // Unique pointer custom clone function @@ -2073,6 +2087,20 @@ class EnumItem : public VisItem Item::Kind get_item_kind () const override { return Item::Kind::EnumItem; } + bool has_expr () { return expression != nullptr; } + + Expr &get_expr () + { + rust_assert (expression != nullptr); + return *expression; + } + + std::unique_ptr &get_expr_ptr () + { + rust_assert (expression != nullptr); + return expression; + } + protected: EnumItem *clone_item_impl () const override { return new EnumItem (*this); } }; @@ -2161,72 +2189,6 @@ class EnumItemStruct : public EnumItem } }; -// A discriminant (numbered enum) item used in an "enum" tagged union -class EnumItemDiscriminant : public EnumItem -{ - std::unique_ptr expression; - -public: - EnumItemDiscriminant (Identifier variant_name, Visibility vis, - std::unique_ptr expr, - std::vector outer_attrs, location_t locus) - : EnumItem (std::move (variant_name), std::move (vis), - std::move (outer_attrs), locus), - expression (std::move (expr)) - {} - - // Copy constructor with clone - EnumItemDiscriminant (EnumItemDiscriminant const &other) - : EnumItem (other), expression (other.expression->clone_expr ()) - {} - - // Overloaded assignment operator to clone - EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other) - { - EnumItem::operator= (other); - expression = other.expression->clone_expr (); - // variant_name = other.variant_name; - // outer_attrs = other.outer_attrs; - - return *this; - } - - // move constructors - EnumItemDiscriminant (EnumItemDiscriminant &&other) = default; - EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default; - - EnumItem::Kind get_enum_item_kind () const override - { - return EnumItem::Kind::Discriminant; - } - - std::string as_string () const override; - - void accept_vis (ASTVisitor &vis) override; - - bool has_expr () { return expression != nullptr; } - - // TODO: is this better? Or is a "vis_block" better? - Expr &get_expr () - { - rust_assert (expression != nullptr); - return *expression; - } - - std::unique_ptr &get_expr_ptr () - { - rust_assert (expression != nullptr); - return expression; - } - -protected: - // Clone function implementation as (not pure) virtual method - EnumItemDiscriminant *clone_item_impl () const override - { - return new EnumItemDiscriminant (*this); - } -}; - // AST node for Rust "enum" - tagged union class Enum : public VisItem { diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 33fb64f0ff2d..f6e74bce3f23 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -1940,27 +1940,6 @@ CfgStrip::visit (AST::EnumItemStruct &item) maybe_strip_struct_fields (item.get_struct_fields ()); } -void -CfgStrip::visit (AST::EnumItemDiscriminant &item) -{ - // initial test based on outer attrs - expand_cfg_attrs (item.get_outer_attrs ()); - if (fails_cfg_with_expand (item.get_outer_attrs ())) - { - item.mark_for_strip (); - return; - } - - AST::DefaultASTVisitor::visit (item); - /* strip any internal sub-expressions - expression itself isn't - * allowed to have external attributes in this position so can't be - * stripped. */ - auto &expr = item.get_expr (); - if (expr.is_marked_for_strip ()) - rust_error_at (expr.get_locus (), - "cannot strip expression in this position - outer " - "attributes not allowed"); -} void CfgStrip::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index 9f1f21172608..ed2a3f9c121c 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -142,7 +142,6 @@ class CfgStrip : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index ef7752b03eec..e86a3a8be9b5 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -160,7 +160,6 @@ class DeriveVisitor : public AST::ASTVisitor virtual void visit (EnumItem &item) override final{}; virtual void visit (EnumItemTuple &item) override final{}; virtual void visit (EnumItemStruct &item) override final{}; - virtual void visit (EnumItemDiscriminant &item) override final{}; virtual void visit (ConstantItem &const_item) override final{}; virtual void visit (StaticItem &static_item) override final{}; virtual void visit (TraitItemConst &item) override final{}; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index e40597e3bc89..a6570868d371 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -798,12 +798,6 @@ ExpandVisitor::visit (AST::EnumItemStruct &item) expand_struct_fields (item.get_struct_fields ()); } -void -ExpandVisitor::visit (AST::EnumItemDiscriminant &item) -{ - maybe_expand_expr (item.get_expr_ptr ()); -} - void ExpandVisitor::visit (AST::Union &union_item) { diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index c353689b2c52..522440386834 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -248,7 +248,6 @@ class ExpandVisitor : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; void visit (AST::StaticItem &static_item) override; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index eac2cba5c752..c41f4c038197 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -325,9 +325,6 @@ void ASTLoweringBase::visit (AST::EnumItemStruct &) {} void -ASTLoweringBase::visit (AST::EnumItemDiscriminant &) -{} -void ASTLoweringBase::visit (AST::Enum &) {} void diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 203b7026e73f..15e66a2eb5fd 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -177,7 +177,6 @@ class ASTLoweringBase : public AST::ASTVisitor virtual void visit (AST::EnumItem &item); virtual void visit (AST::EnumItemTuple &item); virtual void visit (AST::EnumItemStruct &item); - virtual void visit (AST::EnumItemDiscriminant &item); virtual void visit (AST::Enum &enum_item); virtual void visit (AST::Union &union_item); virtual void visit (AST::ConstantItem &const_item); diff --git a/gcc/rust/hir/rust-ast-lower-enumitem.h b/gcc/rust/hir/rust-ast-lower-enumitem.h index 57b9c3790832..10dba25a94c5 100644 --- a/gcc/rust/hir/rust-ast-lower-enumitem.h +++ b/gcc/rust/hir/rust-ast-lower-enumitem.h @@ -144,26 +144,6 @@ class ASTLoweringEnumItem : public ASTLoweringBase item.get_locus ()); } - void visit (AST::EnumItemDiscriminant &item) override - { - auto crate_num = mappings.get_current_crate (); - Analysis::NodeMapping mapping (crate_num, item.get_node_id (), - mappings.get_next_hir_id (crate_num), - mappings.get_next_localdef_id (crate_num)); - - if (item.has_visibility ()) - rust_error_at (item.get_locus (), - "visibility qualifier %qs not allowed on enum item", - item.get_visibility ().as_string ().c_str ()); - - HIR::Expr *expr = ASTLoweringExpr::translate (item.get_expr ()); - translated - = new HIR::EnumItemDiscriminant (mapping, item.get_identifier (), - std::unique_ptr (expr), - item.get_outer_attrs (), - item.get_locus ()); - } - private: ASTLoweringEnumItem () : translated (nullptr) {} diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 65d6a79f571c..f59b2c312a26 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4793,11 +4793,9 @@ Parser::parse_enum_item () std::unique_ptr discriminant_expr = parse_expr (); - return std::unique_ptr ( - new AST::EnumItemDiscriminant (std::move (item_name), std::move (vis), - std::move (discriminant_expr), - std::move (outer_attrs), - item_name_tok->get_locus ())); + return std::unique_ptr (new AST::EnumItem ( + std::move (item_name), std::move (vis), std::move (outer_attrs), + item_name_tok->get_locus (), discriminant_expr->clone_expr ())); } default: // regular enum with just an identifier @@ -10443,7 +10441,7 @@ Parser::parse_pattern () { lexer.skip_token (); alts.push_back (parse_pattern_no_alt ()); - } + } while (lexer.peek_token ()->get_id () == PIPE); diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 74b2756a576d..6d82e76bd73f 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -399,10 +399,6 @@ void ResolverBase::visit (AST::EnumItemStruct &) {} -void -ResolverBase::visit (AST::EnumItemDiscriminant &) -{} - void ResolverBase::visit (AST::Enum &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index bc3e048050c2..567ee968859e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -126,7 +126,6 @@ class ResolverBase : public AST::ASTVisitor void visit (AST::EnumItem &); void visit (AST::EnumItemTuple &); void visit (AST::EnumItemStruct &); - void visit (AST::EnumItemDiscriminant &); void visit (AST::Enum &); void visit (AST::Union &); void visit (AST::ConstantItem &); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 619efb00ac41..e3366fe3578e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -347,17 +347,6 @@ ResolveItem::visit (AST::EnumItemStruct &item) } } -void -ResolveItem::visit (AST::EnumItemDiscriminant &item) -{ - auto decl = CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ()); - auto path = prefix.append (decl); - auto cpath = canonical_prefix.append (decl); - - mappings.insert_canonical_path (item.get_node_id (), cpath); -} - void ResolveItem::visit (AST::StructStruct &struct_decl) { diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index 1fd2647b0e37..a49027c9d21d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -63,7 +63,6 @@ class ResolveItem : public ResolverBase void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::StructStruct &struct_decl) override; void visit (AST::Union &union_decl) override; void visit (AST::StaticItem &var) override; diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 7118b70d7058..a1af52e87aae 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -220,26 +220,6 @@ class ResolveStmt : public ResolverBase } } - void visit (AST::EnumItemDiscriminant &item) override - { - auto decl = enum_prefix.append ( - CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ())); - auto path = decl; // this ensures we have the correct relative resolution - auto cpath = canonical_prefix.append (decl); - mappings.insert_canonical_path (item.get_node_id (), cpath); - - resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, - [&] (const CanonicalPath &, NodeId, location_t locus) -> void { - rich_location r (line_table, item.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - - // Done, no fields. - } - void visit (AST::StructStruct &struct_decl) override { auto decl diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index ceac7edd3415..bafd84b8a784 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -212,28 +212,6 @@ class ResolveTopLevel : public ResolverBase mappings.insert_module_child (current_module, item.get_node_id ()); } - void visit (AST::EnumItemDiscriminant &item) override - { - auto decl = CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ()); - auto path = prefix.append (decl); - auto cpath = canonical_prefix.append (decl); - - resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, - [&] (const CanonicalPath &, NodeId, location_t locus) -> void { - rich_location r (line_table, item.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - - mappings.insert_canonical_path (item.get_node_id (), cpath); - - NodeId current_module = resolver->peek_current_module_scope (); - mappings.insert_module_child_item (current_module, decl); - mappings.insert_module_child (current_module, item.get_node_id ()); - } - void visit (AST::StructStruct &struct_decl) override { auto decl diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 369003765563..efe2e86fb08d 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -329,12 +329,6 @@ TopLevel::visit (AST::EnumItemStruct &variant) insert_or_error_out (variant.get_identifier (), variant, Namespace::Types); } -void -TopLevel::visit (AST::EnumItemDiscriminant &variant) -{ - insert_or_error_out (variant.get_identifier (), variant, Namespace::Types); -} - void TopLevel::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index 081ad2ddd829..ba25218c64fd 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -159,7 +159,6 @@ class TopLevel : public DefaultResolver void visit (AST::EnumItem &variant) override; void visit (AST::EnumItemTuple &variant) override; void visit (AST::EnumItemStruct &variant) override; - void visit (AST::EnumItemDiscriminant &variant) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 45ebf8c65461..4df509ca3d3b 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -717,10 +717,6 @@ void AttributeChecker::visit (AST::EnumItemStruct &) {} -void -AttributeChecker::visit (AST::EnumItemDiscriminant &) -{} - void AttributeChecker::visit (AST::Enum &enumeration) { diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index c341b3e0a5db..3ce7dd7b757b 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -193,7 +193,6 @@ class AttributeChecker : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; From 54f417a03c9827e650b37ea65b33c90f74af254f Mon Sep 17 00:00:00 2001 From: Om Swaroop Nayak <96killerat96@gmail.com> Date: Mon, 6 Jan 2025 12:28:36 -0800 Subject: [PATCH 2/4] gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit):Removed * ast/rust-ast-collector.h: Removed TokenCollector::visit definition * ast/rust-ast-full-decls.h (class EnumItemDiscriminant):Removed * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):Removed * ast/rust-ast-visitor.h:Removed DefaultASTVisitor::visit definition * ast/rust-ast.cc (EnumItemDiscriminant::as_string):Removed (EnumItemDiscriminant::accept_vis):Removed (FormatArgs::set_outer_attrs): Removed * ast/rust-item.h (class EnumItem): added a discriminant expression attribute with relevant helper functions and a constructor to initialise enum items with discriminant (class EnumItemDiscriminant): Removed * expand/rust-cfg-strip.cc (CfgStrip::visit):Removed * expand/rust-cfg-strip.h:Removed CfgStrip::visit definition * expand/rust-derive.h:Removed CfgStrip::visit definition * expand/rust-expand-visitor.cc (ExpandVisitor::visit):Removed * expand/rust-expand-visitor.h:Removed ExpandVisitor::visit definition * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):Removed * hir/rust-ast-lower-base.h:Removed ASTLoweringBase::visit definition * hir/rust-ast-lower-enumitem.h:Removed visit function * parse/rust-parse-impl.h (Parser::parse_enum_item): removed the EnumItemDiscriminant constructor and added the EnumItem constructor with expression (Parser::parse_pattern): modified * resolve/rust-ast-resolve-base.cc (ResolverBase::visit):Removed * resolve/rust-ast-resolve-base.h:Removed ResolverBase::visit definition * resolve/rust-ast-resolve-item.cc (ResolveItem::visit):Removed * resolve/rust-ast-resolve-item.h:Removed ResolveItem::visit definition * resolve/rust-ast-resolve-stmt.h:Removed visit function * resolve/rust-ast-resolve-toplevel.h:Removed visit function * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):Removed * resolve/rust-toplevel-name-resolver-2.0.h:Removed TopLevel::visit definition * util/rust-attributes.cc (AttributeChecker::visit):Removed * util/rust-attributes.h:Removed AttributeChecker::visit definition Signed-off-by: Om Swaroop Nayak <96killerat96@gmail.com> --- gcc/rust/ast/rust-ast-collector.cc | 9 -- gcc/rust/ast/rust-ast-collector.h | 1 - gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast-visitor.cc | 7 -- gcc/rust/ast/rust-ast-visitor.h | 2 - gcc/rust/ast/rust-ast.cc | 21 +--- gcc/rust/ast/rust-item.h | 96 ++++++------------- gcc/rust/expand/rust-cfg-strip.cc | 21 ---- gcc/rust/expand/rust-cfg-strip.h | 1 - gcc/rust/expand/rust-derive.h | 1 - gcc/rust/expand/rust-expand-visitor.cc | 6 -- gcc/rust/expand/rust-expand-visitor.h | 1 - gcc/rust/hir/rust-ast-lower-base.cc | 3 - gcc/rust/hir/rust-ast-lower-base.h | 1 - gcc/rust/hir/rust-ast-lower-enumitem.h | 20 ---- gcc/rust/parse/rust-parse-impl.h | 10 +- gcc/rust/resolve/rust-ast-resolve-base.cc | 4 - gcc/rust/resolve/rust-ast-resolve-base.h | 1 - gcc/rust/resolve/rust-ast-resolve-item.cc | 11 --- gcc/rust/resolve/rust-ast-resolve-item.h | 1 - gcc/rust/resolve/rust-ast-resolve-stmt.h | 20 ---- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 22 ----- .../rust-toplevel-name-resolver-2.0.cc | 6 -- .../resolve/rust-toplevel-name-resolver-2.0.h | 1 - gcc/rust/util/rust-attributes.cc | 4 - gcc/rust/util/rust-attributes.h | 1 - 26 files changed, 35 insertions(+), 237 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 8f66742d1196..ff6c12e147ad 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -1881,15 +1881,6 @@ TokenCollector::visit (EnumItemStruct &item) {Rust::Token::make (COMMA, UNDEF_LOCATION)}); } -void -TokenCollector::visit (EnumItemDiscriminant &item) -{ - auto id = item.get_identifier ().as_string (); - push (Rust::Token::make_identifier (item.get_locus (), std::move (id))); - push (Rust::Token::make (EQUAL, UNDEF_LOCATION)); - visit (item.get_expr ()); -} - void TokenCollector::visit (Enum &enumeration) { diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h index ceb161ccc139..69004d619cda 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -323,7 +323,6 @@ class TokenCollector : public ASTVisitor void visit (EnumItem &item); void visit (EnumItemTuple &item); void visit (EnumItemStruct &item); - void visit (EnumItemDiscriminant &item); void visit (Enum &enumeration); void visit (Union &union_item); void visit (ConstantItem &const_item); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index fffeb1b34660..e235758d4b18 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -188,7 +188,6 @@ class TupleStruct; class EnumItem; class EnumItemTuple; class EnumItemStruct; -class EnumItemDiscriminant; class Enum; class Union; class ConstantItem; diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 7c5117d48dbb..c751c0ac2ac6 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -920,13 +920,6 @@ DefaultASTVisitor::visit (AST::EnumItemStruct &item) visit (field); } -void -DefaultASTVisitor::visit (AST::EnumItemDiscriminant &item) -{ - visit (reinterpret_cast (item)); - visit (item.get_expr ()); -} - void DefaultASTVisitor::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 42513fe22d3c..9b85389c269f 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -157,7 +157,6 @@ class ASTVisitor virtual void visit (EnumItem &item) = 0; virtual void visit (EnumItemTuple &item) = 0; virtual void visit (EnumItemStruct &item) = 0; - virtual void visit (EnumItemDiscriminant &item) = 0; virtual void visit (Enum &enum_item) = 0; virtual void visit (Union &union_item) = 0; virtual void visit (ConstantItem &const_item) = 0; @@ -335,7 +334,6 @@ class DefaultASTVisitor : public ASTVisitor virtual void visit (AST::EnumItem &item) override; virtual void visit (AST::EnumItemTuple &item) override; virtual void visit (AST::EnumItemStruct &item) override; - virtual void visit (AST::EnumItemDiscriminant &item) override; virtual void visit (AST::Enum &enum_item) override; virtual void visit (AST::Union &union_item) override; virtual void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index f32f0caa3176..760ac0fb8465 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2952,18 +2952,6 @@ StructField::as_string () const return str; } -std::string -EnumItemDiscriminant::as_string () const -{ - // TODO: rewrite to work with non-linearisable exprs - std::string str = EnumItem::as_string (); - - // add equal and expression - str += " = " + expression->as_string (); - - return str; -} - std::string ExternalTypeItem::as_string () const { @@ -4765,12 +4753,6 @@ EnumItemStruct::accept_vis (ASTVisitor &vis) vis.visit (*this); } -void -EnumItemDiscriminant::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - void Enum::accept_vis (ASTVisitor &vis) { @@ -5060,7 +5042,8 @@ FormatArgs::get_outer_attrs () rust_unreachable (); } -void FormatArgs::set_outer_attrs (std::vector) +void +FormatArgs::set_outer_attrs (std::vector) { rust_unreachable (); } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 6c9789d5999b..037b889479c7 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2006,6 +2006,8 @@ class EnumItem : public VisItem location_t locus; + std::unique_ptr expression; + public: enum class Kind { @@ -2039,7 +2041,6 @@ class EnumItem : public VisItem // // gccrs#3340 - Discriminant, }; virtual ~EnumItem () {} @@ -2050,6 +2051,19 @@ class EnumItem : public VisItem variant_name (std::move (variant_name)), locus (locus) {} + EnumItem (Identifier variant_name, Visibility vis, + std::vector outer_attrs, location_t locus, + std::unique_ptr Discriminant) + : VisItem (std::move (vis), std::move (outer_attrs)), + variant_name (std::move (variant_name)), locus (locus), + expression (Discriminant->clone_expr ()) + {} + + EnumItem (EnumItem const &other) + : VisItem (other), variant_name (other.variant_name), locus (other.locus), + expression (other.expression->clone_expr ()) + {} + virtual Kind get_enum_item_kind () const { return Kind::Identifier; } // Unique pointer custom clone function @@ -2073,6 +2087,20 @@ class EnumItem : public VisItem Item::Kind get_item_kind () const override { return Item::Kind::EnumItem; } + bool has_expr () { return expression != nullptr; } + + Expr &get_expr () + { + rust_assert (expression != nullptr); + return *expression; + } + + std::unique_ptr &get_expr_ptr () + { + rust_assert (expression != nullptr); + return expression; + } + protected: EnumItem *clone_item_impl () const override { return new EnumItem (*this); } }; @@ -2161,72 +2189,6 @@ class EnumItemStruct : public EnumItem } }; -// A discriminant (numbered enum) item used in an "enum" tagged union -class EnumItemDiscriminant : public EnumItem -{ - std::unique_ptr expression; - -public: - EnumItemDiscriminant (Identifier variant_name, Visibility vis, - std::unique_ptr expr, - std::vector outer_attrs, location_t locus) - : EnumItem (std::move (variant_name), std::move (vis), - std::move (outer_attrs), locus), - expression (std::move (expr)) - {} - - // Copy constructor with clone - EnumItemDiscriminant (EnumItemDiscriminant const &other) - : EnumItem (other), expression (other.expression->clone_expr ()) - {} - - // Overloaded assignment operator to clone - EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other) - { - EnumItem::operator= (other); - expression = other.expression->clone_expr (); - // variant_name = other.variant_name; - // outer_attrs = other.outer_attrs; - - return *this; - } - - // move constructors - EnumItemDiscriminant (EnumItemDiscriminant &&other) = default; - EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default; - - EnumItem::Kind get_enum_item_kind () const override - { - return EnumItem::Kind::Discriminant; - } - - std::string as_string () const override; - - void accept_vis (ASTVisitor &vis) override; - - bool has_expr () { return expression != nullptr; } - - // TODO: is this better? Or is a "vis_block" better? - Expr &get_expr () - { - rust_assert (expression != nullptr); - return *expression; - } - - std::unique_ptr &get_expr_ptr () - { - rust_assert (expression != nullptr); - return expression; - } - -protected: - // Clone function implementation as (not pure) virtual method - EnumItemDiscriminant *clone_item_impl () const override - { - return new EnumItemDiscriminant (*this); - } -}; - // AST node for Rust "enum" - tagged union class Enum : public VisItem { diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 33fb64f0ff2d..f6e74bce3f23 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -1940,27 +1940,6 @@ CfgStrip::visit (AST::EnumItemStruct &item) maybe_strip_struct_fields (item.get_struct_fields ()); } -void -CfgStrip::visit (AST::EnumItemDiscriminant &item) -{ - // initial test based on outer attrs - expand_cfg_attrs (item.get_outer_attrs ()); - if (fails_cfg_with_expand (item.get_outer_attrs ())) - { - item.mark_for_strip (); - return; - } - - AST::DefaultASTVisitor::visit (item); - /* strip any internal sub-expressions - expression itself isn't - * allowed to have external attributes in this position so can't be - * stripped. */ - auto &expr = item.get_expr (); - if (expr.is_marked_for_strip ()) - rust_error_at (expr.get_locus (), - "cannot strip expression in this position - outer " - "attributes not allowed"); -} void CfgStrip::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index 9f1f21172608..ed2a3f9c121c 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -142,7 +142,6 @@ class CfgStrip : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index ef7752b03eec..e86a3a8be9b5 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -160,7 +160,6 @@ class DeriveVisitor : public AST::ASTVisitor virtual void visit (EnumItem &item) override final{}; virtual void visit (EnumItemTuple &item) override final{}; virtual void visit (EnumItemStruct &item) override final{}; - virtual void visit (EnumItemDiscriminant &item) override final{}; virtual void visit (ConstantItem &const_item) override final{}; virtual void visit (StaticItem &static_item) override final{}; virtual void visit (TraitItemConst &item) override final{}; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index e40597e3bc89..a6570868d371 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -798,12 +798,6 @@ ExpandVisitor::visit (AST::EnumItemStruct &item) expand_struct_fields (item.get_struct_fields ()); } -void -ExpandVisitor::visit (AST::EnumItemDiscriminant &item) -{ - maybe_expand_expr (item.get_expr_ptr ()); -} - void ExpandVisitor::visit (AST::Union &union_item) { diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index c353689b2c52..522440386834 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -248,7 +248,6 @@ class ExpandVisitor : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; void visit (AST::StaticItem &static_item) override; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index eac2cba5c752..c41f4c038197 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -325,9 +325,6 @@ void ASTLoweringBase::visit (AST::EnumItemStruct &) {} void -ASTLoweringBase::visit (AST::EnumItemDiscriminant &) -{} -void ASTLoweringBase::visit (AST::Enum &) {} void diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 203b7026e73f..15e66a2eb5fd 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -177,7 +177,6 @@ class ASTLoweringBase : public AST::ASTVisitor virtual void visit (AST::EnumItem &item); virtual void visit (AST::EnumItemTuple &item); virtual void visit (AST::EnumItemStruct &item); - virtual void visit (AST::EnumItemDiscriminant &item); virtual void visit (AST::Enum &enum_item); virtual void visit (AST::Union &union_item); virtual void visit (AST::ConstantItem &const_item); diff --git a/gcc/rust/hir/rust-ast-lower-enumitem.h b/gcc/rust/hir/rust-ast-lower-enumitem.h index 57b9c3790832..10dba25a94c5 100644 --- a/gcc/rust/hir/rust-ast-lower-enumitem.h +++ b/gcc/rust/hir/rust-ast-lower-enumitem.h @@ -144,26 +144,6 @@ class ASTLoweringEnumItem : public ASTLoweringBase item.get_locus ()); } - void visit (AST::EnumItemDiscriminant &item) override - { - auto crate_num = mappings.get_current_crate (); - Analysis::NodeMapping mapping (crate_num, item.get_node_id (), - mappings.get_next_hir_id (crate_num), - mappings.get_next_localdef_id (crate_num)); - - if (item.has_visibility ()) - rust_error_at (item.get_locus (), - "visibility qualifier %qs not allowed on enum item", - item.get_visibility ().as_string ().c_str ()); - - HIR::Expr *expr = ASTLoweringExpr::translate (item.get_expr ()); - translated - = new HIR::EnumItemDiscriminant (mapping, item.get_identifier (), - std::unique_ptr (expr), - item.get_outer_attrs (), - item.get_locus ()); - } - private: ASTLoweringEnumItem () : translated (nullptr) {} diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 65d6a79f571c..f59b2c312a26 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4793,11 +4793,9 @@ Parser::parse_enum_item () std::unique_ptr discriminant_expr = parse_expr (); - return std::unique_ptr ( - new AST::EnumItemDiscriminant (std::move (item_name), std::move (vis), - std::move (discriminant_expr), - std::move (outer_attrs), - item_name_tok->get_locus ())); + return std::unique_ptr (new AST::EnumItem ( + std::move (item_name), std::move (vis), std::move (outer_attrs), + item_name_tok->get_locus (), discriminant_expr->clone_expr ())); } default: // regular enum with just an identifier @@ -10443,7 +10441,7 @@ Parser::parse_pattern () { lexer.skip_token (); alts.push_back (parse_pattern_no_alt ()); - } + } while (lexer.peek_token ()->get_id () == PIPE); diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 74b2756a576d..6d82e76bd73f 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -399,10 +399,6 @@ void ResolverBase::visit (AST::EnumItemStruct &) {} -void -ResolverBase::visit (AST::EnumItemDiscriminant &) -{} - void ResolverBase::visit (AST::Enum &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index bc3e048050c2..567ee968859e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -126,7 +126,6 @@ class ResolverBase : public AST::ASTVisitor void visit (AST::EnumItem &); void visit (AST::EnumItemTuple &); void visit (AST::EnumItemStruct &); - void visit (AST::EnumItemDiscriminant &); void visit (AST::Enum &); void visit (AST::Union &); void visit (AST::ConstantItem &); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 619efb00ac41..e3366fe3578e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -347,17 +347,6 @@ ResolveItem::visit (AST::EnumItemStruct &item) } } -void -ResolveItem::visit (AST::EnumItemDiscriminant &item) -{ - auto decl = CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ()); - auto path = prefix.append (decl); - auto cpath = canonical_prefix.append (decl); - - mappings.insert_canonical_path (item.get_node_id (), cpath); -} - void ResolveItem::visit (AST::StructStruct &struct_decl) { diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index 1fd2647b0e37..a49027c9d21d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -63,7 +63,6 @@ class ResolveItem : public ResolverBase void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::StructStruct &struct_decl) override; void visit (AST::Union &union_decl) override; void visit (AST::StaticItem &var) override; diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 7118b70d7058..a1af52e87aae 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -220,26 +220,6 @@ class ResolveStmt : public ResolverBase } } - void visit (AST::EnumItemDiscriminant &item) override - { - auto decl = enum_prefix.append ( - CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ())); - auto path = decl; // this ensures we have the correct relative resolution - auto cpath = canonical_prefix.append (decl); - mappings.insert_canonical_path (item.get_node_id (), cpath); - - resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, - [&] (const CanonicalPath &, NodeId, location_t locus) -> void { - rich_location r (line_table, item.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - - // Done, no fields. - } - void visit (AST::StructStruct &struct_decl) override { auto decl diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index ceac7edd3415..bafd84b8a784 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -212,28 +212,6 @@ class ResolveTopLevel : public ResolverBase mappings.insert_module_child (current_module, item.get_node_id ()); } - void visit (AST::EnumItemDiscriminant &item) override - { - auto decl = CanonicalPath::new_seg (item.get_node_id (), - item.get_identifier ().as_string ()); - auto path = prefix.append (decl); - auto cpath = canonical_prefix.append (decl); - - resolver->get_type_scope ().insert ( - path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type, - [&] (const CanonicalPath &, NodeId, location_t locus) -> void { - rich_location r (line_table, item.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - - mappings.insert_canonical_path (item.get_node_id (), cpath); - - NodeId current_module = resolver->peek_current_module_scope (); - mappings.insert_module_child_item (current_module, decl); - mappings.insert_module_child (current_module, item.get_node_id ()); - } - void visit (AST::StructStruct &struct_decl) override { auto decl diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 369003765563..efe2e86fb08d 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -329,12 +329,6 @@ TopLevel::visit (AST::EnumItemStruct &variant) insert_or_error_out (variant.get_identifier (), variant, Namespace::Types); } -void -TopLevel::visit (AST::EnumItemDiscriminant &variant) -{ - insert_or_error_out (variant.get_identifier (), variant, Namespace::Types); -} - void TopLevel::visit (AST::Enum &enum_item) { diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index 081ad2ddd829..ba25218c64fd 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -159,7 +159,6 @@ class TopLevel : public DefaultResolver void visit (AST::EnumItem &variant) override; void visit (AST::EnumItemTuple &variant) override; void visit (AST::EnumItemStruct &variant) override; - void visit (AST::EnumItemDiscriminant &variant) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 45ebf8c65461..4df509ca3d3b 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -717,10 +717,6 @@ void AttributeChecker::visit (AST::EnumItemStruct &) {} -void -AttributeChecker::visit (AST::EnumItemDiscriminant &) -{} - void AttributeChecker::visit (AST::Enum &enumeration) { diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index c341b3e0a5db..3ce7dd7b757b 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -193,7 +193,6 @@ class AttributeChecker : public AST::DefaultASTVisitor void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; - void visit (AST::EnumItemDiscriminant &item) override; void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; From ea9ed375f6ee5c815519142e12a1a0ff0f0bb27e Mon Sep 17 00:00:00 2001 From: Om Swaroop Nayak <146124307+saeitoshi-10@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:17:15 +0530 Subject: [PATCH 3/4] Update rust-ast.cc --- gcc/rust/ast/rust-ast.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 760ac0fb8465..4aeb49bed918 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -5042,8 +5042,7 @@ FormatArgs::get_outer_attrs () rust_unreachable (); } -void -FormatArgs::set_outer_attrs (std::vector) +void FormatArgs::set_outer_attrs (std::vector) { rust_unreachable (); } From 057c7e625e16eb4e7ca18193a25f8fd5bf6a1a5a Mon Sep 17 00:00:00 2001 From: Om Swaroop Nayak <146124307+saeitoshi-10@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:19:45 +0530 Subject: [PATCH 4/4] Update rust-parse-impl.h --- gcc/rust/parse/rust-parse-impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index f59b2c312a26..30aa03de5f4c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -10441,7 +10441,7 @@ Parser::parse_pattern () { lexer.skip_token (); alts.push_back (parse_pattern_no_alt ()); - } + } while (lexer.peek_token ()->get_id () == PIPE);