diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-07-25 13:29:31 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-07-27 15:30:09 +0200 |
commit | 53aee096bd22a43165839f908581753ab987e9d9 (patch) | |
tree | b2d7cf5d90794d168526987c4fa2f7bc173f7eb8 | |
parent | d94d5b1ea23220d423fd40bd00cadb0e6ede751f (diff) | |
download | gcc-53aee096bd22a43165839f908581753ab987e9d9.zip gcc-53aee096bd22a43165839f908581753ab987e9d9.tar.gz gcc-53aee096bd22a43165839f908581753ab987e9d9.tar.bz2 |
hir: Add Item::ItemKind enumeration
This allows us to perform checks and dispatch when getting an HIR::Item*
from Mappings::lookup_hir_item()
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 25 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 0d41bd0..6156b2d 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 58f4db2..c2f6fef 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 { |