From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 4E4E1385841D; Thu, 28 Jul 2022 07:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E4E1385841D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] hir: Add Item::ItemKind enumeration X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: d94d5b1ea23220d423fd40bd00cadb0e6ede751f X-Git-Newrev: 53aee096bd22a43165839f908581753ab987e9d9 Message-Id: <20220728075309.4E4E1385841D@sourceware.org> Date: Thu, 28 Jul 2022 07:53:09 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2022 07:53:09 -0000 https://gcc.gnu.org/g:53aee096bd22a43165839f908581753ab987e9d9 commit 53aee096bd22a43165839f908581753ab987e9d9 Author: Arthur Cohen Date: Mon Jul 25 13:29:31 2022 +0200 hir: Add Item::ItemKind enumeration This allows us to perform checks and dispatch when getting an HIR::Item* from Mappings::lookup_hir_item() Diff: --- gcc/rust/hir/tree/rust-hir-item.h | 25 +++++++++++++++++++++++++ gcc/rust/hir/tree/rust-hir.h | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 0d41bd0bbb0..6156b2dacb3 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -723,6 +723,8 @@ public: Location get_locus () const override final { return locus; } + ItemKind get_item_kind () const override { return ItemKind::Module; } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -773,6 +775,8 @@ public: Location get_locus () const override final { return locus; } + ItemKind get_item_kind () const override { return ItemKind::ExternCrate; } + void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRStmtVisitor &vis) override; void accept_vis (HIRVisItemVisitor &vis) override; @@ -1039,6 +1043,7 @@ public: UseDeclaration &operator= (UseDeclaration &&other) = default; Location get_locus () const override final { return locus; } + ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRStmtVisitor &vis) override; @@ -1094,6 +1099,8 @@ public: return ImplItem::ImplItemType::FUNCTION; } + ItemKind get_item_kind () const override { return ItemKind::Function; } + // Mega-constructor with all possible fields Function (Analysis::NodeMapping mappings, Identifier function_name, FunctionQualifiers qualifiers, @@ -1329,6 +1336,8 @@ public: Identifier get_new_type_name () const { return new_type_name; } + ItemKind get_item_kind () const override { return ItemKind::TypeAlias; } + Analysis::NodeMapping get_impl_mappings () const override { return get_mappings (); @@ -1373,6 +1382,7 @@ public: bool has_where_clause () const { return !where_clause.is_empty (); } Location get_locus () const override final { return locus; } + ItemKind get_item_kind () const override { return ItemKind::Struct; } std::vector> &get_generic_params () { @@ -1709,6 +1719,8 @@ public: Identifier get_identifier () const { return variant_name; } + ItemKind get_item_kind () const override { return ItemKind::EnumItem; } + protected: EnumItem *clone_item_impl () const override { return new EnumItem (*this); } }; @@ -1930,6 +1942,7 @@ public: void accept_vis (HIRVisItemVisitor &vis) override; Identifier get_identifier () const { return enum_name; } + ItemKind get_item_kind () const override { return ItemKind::Enum; } std::vector> &get_generic_params () { @@ -2037,6 +2050,8 @@ public: WhereClause &get_where_clause () { return where_clause; } + ItemKind get_item_kind () const override { return ItemKind::Union; } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -2111,6 +2126,8 @@ public: return ImplItem::ImplItemType::CONSTANT; } + ItemKind get_item_kind () const override { return ItemKind::Constant; } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -2188,6 +2205,8 @@ public: Type *get_type () { return type.get (); } + ItemKind get_item_kind () const override { return ItemKind::Static; } + protected: StaticItem *clone_item_impl () const override { @@ -2677,6 +2696,8 @@ public: return type_param_bounds; } + ItemKind get_item_kind () const override { return ItemKind::Trait; } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -2797,6 +2818,8 @@ public: WhereClause &get_where_clause () { return where_clause; } + ItemKind get_item_kind () const override { return ItemKind::Impl; } + protected: ImplBlock *clone_item_impl () const override { return new ImplBlock (*this); } }; @@ -3149,6 +3172,8 @@ public: return extern_items; } + ItemKind get_item_kind () const override { return ItemKind::ExternBlock; } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 58f4db2fcc6..c2f6fef1383 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -175,6 +175,26 @@ class Item : public Stmt // TODO: should outer attrs be defined here or in each derived class? public: + enum class ItemKind + { + Static, + Constant, + TypeAlias, + Function, + UseDeclaration, + ExternBlock, + ExternCrate, + Struct, + Union, + Enum, + EnumItem, // FIXME: ARTHUR: Do we need that? + Trait, + Impl, + Module, + }; + + virtual ItemKind get_item_kind () const = 0; + // Unique pointer custom clone function std::unique_ptr clone_item () const {