public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add TraitItemKind to HIR TraitItems
@ 2022-06-08 12:00 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:00 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:120967b80bec0bc4427c61dd94c2f81187223966
commit 120967b80bec0bc4427c61dd94c2f81187223966
Author: Philip Herron <philip.herron@embecosm.com>
Date: Fri Jan 21 19:59:02 2022 +0000
Add TraitItemKind to HIR TraitItems
This allows us to safely switch and cast between the items without the
need for visitors.
Diff:
---
gcc/rust/hir/tree/rust-hir-full-test.cc | 4 ++--
gcc/rust/hir/tree/rust-hir-item.h | 15 +++++++++++++++
gcc/rust/hir/tree/rust-hir.h | 10 ++++++++++
3 files changed, 27 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 adc8eeae55e..4391f39d304 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -3453,7 +3453,7 @@ TraitFunctionDecl::as_string () const
str += "\n Function params: ";
if (is_method ())
{
- str += self.as_string ();
+ str += self.as_string () + (has_params () ? ", " : "");
}
if (has_params ())
@@ -3463,7 +3463,7 @@ TraitFunctionDecl::as_string () const
str += "\n " + param.as_string ();
}
}
- else
+ else if (!is_method ())
{
str += "none";
}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 09f9d381ef5..3afea36b9c6 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -2346,6 +2346,11 @@ public:
return decl.get_function_name ();
}
+ TraitItemKind get_item_kind () const override final
+ {
+ return TraitItemKind::FUNC;
+ }
+
protected:
// Clone function implementation as (not pure) virtual method
TraitItemFunc *clone_trait_item_impl () const override
@@ -2420,6 +2425,11 @@ public:
const std::string trait_identifier () const override final { return name; }
+ TraitItemKind get_item_kind () const override final
+ {
+ return TraitItemKind::CONST;
+ }
+
protected:
// Clone function implementation as (not pure) virtual method
TraitItemConst *clone_trait_item_impl () const override
@@ -2495,6 +2505,11 @@ public:
const std::string trait_identifier () const override final { return name; }
+ TraitItemKind get_item_kind () const override final
+ {
+ return TraitItemKind::TYPE;
+ }
+
protected:
// Clone function implementation as (not pure) virtual method
TraitItemType *clone_trait_item_impl () const override
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index de312eed869..76d451ca8e8 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -677,6 +677,14 @@ protected:
// Item used in trait declarations - abstract base class
class TraitItem
{
+public:
+ enum TraitItemKind
+ {
+ FUNC,
+ CONST,
+ TYPE
+ };
+
protected:
// Constructor
TraitItem (Analysis::NodeMapping mappings) : mappings (mappings) {}
@@ -701,6 +709,8 @@ public:
virtual const std::string trait_identifier () const = 0;
const Analysis::NodeMapping get_mappings () const { return mappings; }
+
+ virtual TraitItemKind get_item_kind () const = 0;
};
class ImplItem
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:00 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:00 [gcc/devel/rust/master] Add TraitItemKind to HIR TraitItems 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).