aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-01-21 19:59:02 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-01-21 20:01:32 +0000
commit120967b80bec0bc4427c61dd94c2f81187223966 (patch)
tree5f51710223665cfd092533086fb0266cb0e99b80
parenta6c5dbadc3c9023821244bd4af4e78ad9d8f63f2 (diff)
downloadgcc-120967b80bec0bc4427c61dd94c2f81187223966.zip
gcc-120967b80bec0bc4427c61dd94c2f81187223966.tar.gz
gcc-120967b80bec0bc4427c61dd94c2f81187223966.tar.bz2
Add TraitItemKind to HIR TraitItems
This allows us to safely switch and cast between the items without the need for visitors.
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc4
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h15
-rw-r--r--gcc/rust/hir/tree/rust-hir.h10
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 adc8eea..4391f39 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 09f9d38..3afea36 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 de312ee..76d451c 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