public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: add error state to TypeCheckContextItem and missing copy ctor's
@ 2023-05-02 7:10 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-05-02 7:10 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:198f98ec04c9f09f956fee36cfb93957e06fbe7d
commit 198f98ec04c9f09f956fee36cfb93957e06fbe7d
Author: Philip Herron <herron.philip@googlemail.com>
Date: Tue Apr 18 12:36:29 2023 +0100
gccrs: add error state to TypeCheckContextItem and missing copy ctor's
When checking current context we might be in the const or static context
which does not have a current function or impl or trait context associated
with it. So this allows us to represent the an error state for that case.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h: New error state and missing copy implementations
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem):
missing copy ctor
(TypeCheckContextItem::operator=): missing copy implementation
(TypeCheckContextItem::get_error): new static function
(TypeCheckContextItem::is_error): new method
(TypeCheckContextItem::get_context_type): handle error state
(TypeCheckContextItem::get_defid): handle error state
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-hir-type-check.h | 10 ++++
gcc/rust/typecheck/rust-typecheck-context.cc | 72 ++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index 74ab6c3cacf..4f8364d798f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -35,11 +35,19 @@ public:
ITEM,
IMPL_ITEM,
TRAIT_ITEM,
+ ERROR
};
TypeCheckContextItem (HIR::Function *item);
TypeCheckContextItem (HIR::ImplBlock *impl_block, HIR::Function *item);
TypeCheckContextItem (HIR::TraitItemFunc *trait_item);
+ TypeCheckContextItem (const TypeCheckContextItem &other);
+
+ TypeCheckContextItem &operator= (const TypeCheckContextItem &other);
+
+ static TypeCheckContextItem get_error ();
+
+ bool is_error () const;
ItemType get_type () const;
@@ -54,6 +62,8 @@ public:
DefId get_defid () const;
private:
+ TypeCheckContextItem ();
+
union Item
{
HIR::Function *item;
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index ffa49dc195b..2e3a6284fb1 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -525,6 +525,71 @@ TypeCheckContextItem::TypeCheckContextItem (HIR::TraitItemFunc *trait_item)
: type (ItemType::TRAIT_ITEM), item (trait_item)
{}
+TypeCheckContextItem::TypeCheckContextItem (const TypeCheckContextItem &other)
+ : type (other.type), item (other.item)
+{
+ switch (other.type)
+ {
+ case ITEM:
+ item.item = other.item.item;
+ break;
+
+ case IMPL_ITEM:
+ item.impl_item = other.item.impl_item;
+ break;
+
+ case TRAIT_ITEM:
+ item.trait_item = other.item.trait_item;
+ break;
+
+ case ERROR:
+ item.item = nullptr;
+ break;
+ }
+}
+
+TypeCheckContextItem::TypeCheckContextItem ()
+ : type (ItemType::ERROR), item (static_cast<HIR::Function *> (nullptr))
+{}
+
+TypeCheckContextItem &
+TypeCheckContextItem::operator= (const TypeCheckContextItem &other)
+{
+ type = other.type;
+ switch (other.type)
+ {
+ case ITEM:
+ item.item = other.item.item;
+ break;
+
+ case IMPL_ITEM:
+ item.impl_item = other.item.impl_item;
+ break;
+
+ case TRAIT_ITEM:
+ item.trait_item = other.item.trait_item;
+ break;
+
+ case ERROR:
+ item.item = nullptr;
+ break;
+ }
+
+ return *this;
+}
+
+TypeCheckContextItem
+TypeCheckContextItem::get_error ()
+{
+ return TypeCheckContextItem ();
+}
+
+bool
+TypeCheckContextItem::is_error () const
+{
+ return type == ERROR;
+}
+
HIR::Function *
TypeCheckContextItem::get_item ()
{
@@ -571,6 +636,10 @@ TypeCheckContextItem::get_context_type ()
case TRAIT_ITEM:
reference = get_trait_item ()->get_mappings ().get_hirid ();
break;
+
+ case ERROR:
+ gcc_unreachable ();
+ return nullptr;
}
rust_assert (reference != UNKNOWN_HIRID);
@@ -595,6 +664,9 @@ TypeCheckContextItem::get_defid () const
case TRAIT_ITEM:
return item.trait_item->get_mappings ().get_defid ();
+
+ case ERROR:
+ return UNKNOWN_DEFID;
}
return UNKNOWN_DEFID;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-02 7:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 7:10 [gcc/devel/rust/master] gccrs: add error state to TypeCheckContextItem and missing copy ctor's 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).