aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-02-20 15:45:35 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-08-01 13:11:30 +0200
commit26e77295e77e5e008e0aa43837edd293ca12179e (patch)
tree2ac14ce3a1fe4f0532d6595f611bfff7d7242195 /gcc/rust/hir/tree
parentcac2e9715a7d35d869962a724cd4e0834a8d4438 (diff)
downloadgcc-26e77295e77e5e008e0aa43837edd293ca12179e.zip
gcc-26e77295e77e5e008e0aa43837edd293ca12179e.tar.gz
gcc-26e77295e77e5e008e0aa43837edd293ca12179e.tar.bz2
gccrs: hir: Add ExternalTypeItem node
gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h (class ExternalTypeItem): New class. * hir/tree/rust-hir.cc (ExternalTypeItem::as_string): Likewise. * backend/rust-compile-extern.h: Add base for handling HIR::ExternalTypeItem node. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-full-decls.h (class ExternalTypeItem): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. (ExternalTypeItem::accept_vis): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. * typecheck/rust-hir-type-check-implitem.h: Likewise.
Diffstat (limited to 'gcc/rust/hir/tree')
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h1
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h39
-rw-r--r--gcc/rust/hir/tree/rust-hir-visitor.h3
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc25
4 files changed, 65 insertions, 3 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index 96293ce..d01535e 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -177,6 +177,7 @@ class ExternalItem;
class ExternalStaticItem;
struct NamedFunctionParam;
class ExternalFunctionItem;
+class ExternalTypeItem;
class ExternBlock;
// rust-pattern.h
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 1d067fc..40093a2 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -2859,6 +2859,7 @@ public:
{
Static,
Function,
+ Type,
};
virtual ~ExternalItem () {}
@@ -3084,11 +3085,13 @@ public:
// Copy constructor with clone
ExternalFunctionItem (ExternalFunctionItem const &other)
- : ExternalItem (other), return_type (other.return_type->clone_type ()),
- where_clause (other.where_clause),
+ : ExternalItem (other), where_clause (other.where_clause),
function_params (other.function_params),
has_variadics (other.has_variadics)
{
+ if (other.return_type)
+ return_type = other.return_type->clone_type ();
+
generic_params.reserve (other.generic_params.size ());
for (const auto &e : other.generic_params)
generic_params.push_back (e->clone_generic_param ());
@@ -3098,11 +3101,14 @@ public:
ExternalFunctionItem &operator= (ExternalFunctionItem const &other)
{
ExternalItem::operator= (other);
- return_type = other.return_type->clone_type ();
+
where_clause = other.where_clause;
function_params = other.function_params;
has_variadics = other.has_variadics;
+ if (other.return_type)
+ return_type = other.return_type->clone_type ();
+
generic_params.reserve (other.generic_params.size ());
for (const auto &e : other.generic_params)
generic_params.push_back (e->clone_generic_param ());
@@ -3144,6 +3150,33 @@ protected:
}
};
+class ExternalTypeItem : public ExternalItem
+{
+ ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name,
+ Visibility vis, AST::AttrVec outer_attrs, location_t locus)
+ : ExternalItem (std::move (mappings), std::move (item_name),
+ std::move (vis), std::move (outer_attrs), locus)
+ {}
+
+ ExternalTypeItem (ExternalTypeItem const &other) : ExternalItem (other) {}
+
+ ExternalTypeItem (ExternalTypeItem &&other) = default;
+ ExternalTypeItem &operator= (ExternalTypeItem &&other) = default;
+
+ std::string as_string () const override;
+
+ void accept_vis (HIRFullVisitor &vis) override;
+ void accept_vis (HIRExternalItemVisitor &vis) override;
+
+ ExternKind get_extern_kind () override { return ExternKind::Type; }
+
+protected:
+ ExternalTypeItem *clone_external_item_impl () const override
+ {
+ return new ExternalTypeItem (*this);
+ }
+};
+
// An extern block HIR node
class ExternBlock : public VisItem, public WithInnerAttrs
{
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h
index 4e7a97b..ae9d23f 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -114,6 +114,7 @@ public:
virtual void visit (ImplBlock &impl) = 0;
virtual void visit (ExternalStaticItem &item) = 0;
virtual void visit (ExternalFunctionItem &item) = 0;
+ virtual void visit (ExternalTypeItem &item) = 0;
virtual void visit (ExternBlock &block) = 0;
virtual void visit (LiteralPattern &pattern) = 0;
virtual void visit (IdentifierPattern &pattern) = 0;
@@ -255,6 +256,7 @@ public:
virtual void visit (ExternalStaticItem &) override {}
virtual void visit (ExternalFunctionItem &) override {}
+ virtual void visit (ExternalTypeItem &) override {}
virtual void visit (ExternBlock &) override {}
virtual void visit (LiteralPattern &) override {}
@@ -306,6 +308,7 @@ class HIRExternalItemVisitor
public:
virtual void visit (ExternalStaticItem &item) = 0;
virtual void visit (ExternalFunctionItem &item) = 0;
+ virtual void visit (ExternalTypeItem &item) = 0;
};
class HIRTraitItemVisitor
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index fb0a9c3..3eb8838 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -3257,6 +3257,19 @@ ExternalFunctionItem::as_string () const
}
std::string
+ExternalTypeItem::as_string () const
+{
+ std::string str = ExternalItem::as_string ();
+
+ str += "type ";
+
+ // add name
+ str += get_item_name ().as_string ();
+
+ return str;
+}
+
+std::string
NamedFunctionParam::as_string () const
{
std::string str = name.as_string ();
@@ -4273,6 +4286,12 @@ ExternalFunctionItem::accept_vis (HIRFullVisitor &vis)
}
void
+ExternalTypeItem::accept_vis (HIRFullVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
ExternBlock::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4543,6 +4562,12 @@ ExternalFunctionItem::accept_vis (HIRExternalItemVisitor &vis)
}
void
+ExternalTypeItem::accept_vis (HIRExternalItemVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
ExternalStaticItem::accept_vis (HIRExternalItemVisitor &vis)
{
vis.visit (*this);