diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-14 10:49:19 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-14 10:49:19 +0200 |
commit | 126f7aecdcdf1bf3044e0a0165324ed3ce258a78 (patch) | |
tree | 4e1bc4daf08c17d61f032c5125cfb8fd2825df6b /gcc | |
parent | 71f2cd57c6fed5d01c56858800bc17cb68a9ac38 (diff) | |
download | gcc-126f7aecdcdf1bf3044e0a0165324ed3ce258a78.zip gcc-126f7aecdcdf1bf3044e0a0165324ed3ce258a78.tar.gz gcc-126f7aecdcdf1bf3044e0a0165324ed3ce258a78.tar.bz2 |
hir: Add `EnumItemKind` enum for EnumItem classes
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-test.cc | 16 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 27 |
2 files changed, 41 insertions, 2 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index 9b56086..a996228 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -3108,6 +3108,22 @@ EnumItem::as_string () const { std::string str = Item::as_string (); str += variant_name; + str += " "; + switch (get_enum_item_kind ()) + { + case Named: + str += "[Named variant]"; + break; + case Tuple: + str += "[Tuple variant]"; + break; + case Struct: + str += "[Struct variant]"; + break; + case Discriminant: + str += "[Discriminant variant]"; + break; + } return str; } diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index bc26725..2f69630 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -1588,7 +1588,7 @@ public: std::string as_string () const; - Analysis::NodeMapping get_mappings () { return mappings; } + Analysis::NodeMapping get_mappings () const { return mappings; } Location get_locus () const { return locus; } @@ -1644,12 +1644,19 @@ protected: class EnumItem : public Item { Identifier variant_name; - Location locus; public: virtual ~EnumItem () {} + enum EnumItemKind + { + Named, + Tuple, + Struct, + Discriminant, + }; + EnumItem (Analysis::NodeMapping mappings, Identifier variant_name, AST::AttrVec outer_attrs, Location locus) : Item (std::move (mappings), std::move (outer_attrs)), @@ -1663,6 +1670,7 @@ public: } virtual std::string as_string () const override; + virtual EnumItemKind get_enum_item_kind () const { return Named; }; // not pure virtual as not abstract void accept_vis (HIRFullVisitor &vis) override; @@ -1687,6 +1695,11 @@ public: // Returns whether tuple enum item has tuple fields. bool has_tuple_fields () const { return !tuple_fields.empty (); } + EnumItemKind get_enum_item_kind () const override + { + return EnumItemKind::Tuple; + } + EnumItemTuple (Analysis::NodeMapping mappings, Identifier variant_name, std::vector<TupleField> tuple_fields, AST::AttrVec outer_attrs, Location locus) @@ -1720,6 +1733,11 @@ public: // Returns whether struct enum item has struct fields. bool has_struct_fields () const { return !struct_fields.empty (); } + EnumItemKind get_enum_item_kind () const override + { + return EnumItemKind::Struct; + } + EnumItemStruct (Analysis::NodeMapping mappings, Identifier variant_name, std::vector<StructField> struct_fields, AST::AttrVec outer_attrs, Location locus) @@ -1777,6 +1795,11 @@ public: EnumItemDiscriminant (EnumItemDiscriminant &&other) = default; EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default; + EnumItemKind get_enum_item_kind () const override + { + return EnumItemKind::Discriminant; + } + std::string as_string () const override; void accept_vis (HIRFullVisitor &vis) override; |