public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] hir: Add `EnumItemKind` enum for EnumItem classes
@ 2022-06-08 12:31 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:126f7aecdcdf1bf3044e0a0165324ed3ce258a78
commit 126f7aecdcdf1bf3044e0a0165324ed3ce258a78
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Thu Apr 14 10:49:19 2022 +0200
hir: Add `EnumItemKind` enum for EnumItem classes
Diff:
---
gcc/rust/hir/tree/rust-hir-full-test.cc | 16 ++++++++++++++++
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 9b56086ea55..a996228ce31 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 bc26725ff0b..2f696307cfe 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:31 [gcc/devel/rust/master] hir: Add `EnumItemKind` enum for EnumItem classes 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).