public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] hir: Add Item::ItemKind enumeration
@ 2022-07-28  7:53 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-28  7:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:53aee096bd22a43165839f908581753ab987e9d9

commit 53aee096bd22a43165839f908581753ab987e9d9
Author: Arthur Cohen <arthur.cohen@embecosm.com>
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<std::unique_ptr<GenericParam>> &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<std::unique_ptr<GenericParam>> &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<Item> clone_item () const
   {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-28  7:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28  7:53 [gcc/devel/rust/master] hir: Add Item::ItemKind enumeration Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).