Skip to content

Commit 8e3c34a

Browse files
committed
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.
1 parent 7b3fa7a commit 8e3c34a

16 files changed

+230
-3
lines changed

gcc/rust/backend/rust-compile-extern.h

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "rust-compile-base.h"
2323
#include "rust-compile-intrinsic.h"
2424
#include "rust-compile-type.h"
25+
#include "rust-diagnostics.h"
26+
#include "rust-hir-full-decls.h"
2527

2628
namespace Rust {
2729
namespace Compile {
@@ -152,6 +154,11 @@ class CompileExternItem : public HIRCompileBase,
152154
reference = address_expression (fndecl, ref_locus);
153155
}
154156

157+
void visit (HIR::ExternalTypeItem &type) override
158+
{
159+
rust_sorry_at (type.get_locus (), "extern types are not supported yet");
160+
}
161+
155162
private:
156163
CompileExternItem (Context *ctx, TyTy::BaseType *concrete,
157164
location_t ref_locus)

gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class StructBuilder : public AbstractBuilder, public HIR::HIRFullVisitor
189189
void visit (HIR::ImplBlock &impl) override { rust_unreachable (); }
190190
void visit (HIR::ExternalStaticItem &item) override { rust_unreachable (); }
191191
void visit (HIR::ExternalFunctionItem &item) override { rust_unreachable (); }
192+
void visit (HIR::ExternalTypeItem &item) override { rust_unreachable (); }
192193
void visit (HIR::ExternBlock &block) override { rust_unreachable (); }
193194
void visit (HIR::LiteralPattern &pattern) override { rust_unreachable (); }
194195
void visit (HIR::IdentifierPattern &pattern) override { rust_unreachable (); }

gcc/rust/checks/errors/borrowck/rust-function-collector.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class FunctionCollector : public HIR::HIRFullVisitor
155155
void visit (HIR::ImplBlock &impl) override {}
156156
void visit (HIR::ExternalStaticItem &item) override {}
157157
void visit (HIR::ExternalFunctionItem &item) override {}
158+
void visit (HIR::ExternalTypeItem &item) override {}
158159
void visit (HIR::ExternBlock &block) override {}
159160
void visit (HIR::LiteralPattern &pattern) override {}
160161
void visit (HIR::IdentifierPattern &pattern) override {}

gcc/rust/checks/errors/rust-const-checker.cc

+4
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,10 @@ void
714714
ConstChecker::visit (ExternalFunctionItem &)
715715
{}
716716

717+
void
718+
ConstChecker::visit (ExternalTypeItem &)
719+
{}
720+
717721
void
718722
ConstChecker::visit (ExternBlock &block)
719723
{

gcc/rust/checks/errors/rust-const-checker.h

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ConstChecker : public HIRFullVisitor
162162
virtual void visit (ImplBlock &impl) override;
163163
virtual void visit (ExternalStaticItem &item) override;
164164
virtual void visit (ExternalFunctionItem &item) override;
165+
virtual void visit (ExternalTypeItem &item) override;
165166
virtual void visit (ExternBlock &block) override;
166167
virtual void visit (LiteralPattern &pattern) override;
167168
virtual void visit (IdentifierPattern &pattern) override;

gcc/rust/checks/errors/rust-unsafe-checker.cc

+4
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@ void
783783
UnsafeChecker::visit (ExternalFunctionItem &)
784784
{}
785785

786+
void
787+
UnsafeChecker::visit (ExternalTypeItem &)
788+
{}
789+
786790
void
787791
UnsafeChecker::visit (ExternBlock &block)
788792
{

gcc/rust/checks/errors/rust-unsafe-checker.h

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class UnsafeChecker : public HIRFullVisitor
144144
virtual void visit (ImplBlock &impl) override;
145145
virtual void visit (ExternalStaticItem &item) override;
146146
virtual void visit (ExternalFunctionItem &item) override;
147+
virtual void visit (ExternalTypeItem &item) override;
147148
virtual void visit (ExternBlock &block) override;
148149
virtual void visit (LiteralPattern &pattern) override;
149150
virtual void visit (IdentifierPattern &pattern) override;

gcc/rust/hir/rust-ast-lower-extern.h

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ASTLoweringExternItem : public ASTLoweringBase
114114
function.get_outer_attrs (), function.get_locus ());
115115
}
116116

117+
void visit (AST::ExternalTypeItem &type) override
118+
{
119+
rust_sorry_at (type.get_locus (), "extern types are not implemented yet");
120+
}
121+
117122
private:
118123
ASTLoweringExternItem () : translated (nullptr) {}
119124

gcc/rust/hir/rust-hir-dump.cc

+10
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,16 @@ Dump::visit (ExternalFunctionItem &e)
19991999
end ("ExternalFunctionItem");
20002000
}
20012001

2002+
void
2003+
Dump::visit (ExternalTypeItem &e)
2004+
{
2005+
begin ("ExternalTypeItem");
2006+
2007+
do_externalitem (e);
2008+
2009+
end ("ExternalTypeItem");
2010+
}
2011+
20022012
void
20032013
Dump::visit (ExternBlock &e)
20042014
{

gcc/rust/hir/rust-hir-dump.h

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class Dump : public HIRFullVisitor
201201

202202
virtual void visit (ExternalStaticItem &) override;
203203
virtual void visit (ExternalFunctionItem &) override;
204+
virtual void visit (ExternalTypeItem &) override;
204205
virtual void visit (ExternBlock &) override;
205206

206207
virtual void visit (LiteralPattern &) override;

gcc/rust/hir/tree/rust-hir-full-decls.h

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class ExternalItem;
177177
class ExternalStaticItem;
178178
struct NamedFunctionParam;
179179
class ExternalFunctionItem;
180+
class ExternalTypeItem;
180181
class ExternBlock;
181182

182183
// rust-pattern.h

gcc/rust/hir/tree/rust-hir-item.h

+36-3
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,7 @@ class ExternalItem : public Node
28592859
{
28602860
Static,
28612861
Function,
2862+
Type,
28622863
};
28632864

28642865
virtual ~ExternalItem () {}
@@ -3084,11 +3085,13 @@ class ExternalFunctionItem : public ExternalItem
30843085

30853086
// Copy constructor with clone
30863087
ExternalFunctionItem (ExternalFunctionItem const &other)
3087-
: ExternalItem (other), return_type (other.return_type->clone_type ()),
3088-
where_clause (other.where_clause),
3088+
: ExternalItem (other), where_clause (other.where_clause),
30893089
function_params (other.function_params),
30903090
has_variadics (other.has_variadics)
30913091
{
3092+
if (other.return_type)
3093+
return_type = other.return_type->clone_type ();
3094+
30923095
generic_params.reserve (other.generic_params.size ());
30933096
for (const auto &e : other.generic_params)
30943097
generic_params.push_back (e->clone_generic_param ());
@@ -3098,11 +3101,14 @@ class ExternalFunctionItem : public ExternalItem
30983101
ExternalFunctionItem &operator= (ExternalFunctionItem const &other)
30993102
{
31003103
ExternalItem::operator= (other);
3101-
return_type = other.return_type->clone_type ();
3104+
31023105
where_clause = other.where_clause;
31033106
function_params = other.function_params;
31043107
has_variadics = other.has_variadics;
31053108

3109+
if (other.return_type)
3110+
return_type = other.return_type->clone_type ();
3111+
31063112
generic_params.reserve (other.generic_params.size ());
31073113
for (const auto &e : other.generic_params)
31083114
generic_params.push_back (e->clone_generic_param ());
@@ -3144,6 +3150,33 @@ class ExternalFunctionItem : public ExternalItem
31443150
}
31453151
};
31463152

3153+
class ExternalTypeItem : public ExternalItem
3154+
{
3155+
ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name,
3156+
Visibility vis, AST::AttrVec outer_attrs, location_t locus)
3157+
: ExternalItem (std::move (mappings), std::move (item_name),
3158+
std::move (vis), std::move (outer_attrs), locus)
3159+
{}
3160+
3161+
ExternalTypeItem (ExternalTypeItem const &other) : ExternalItem (other) {}
3162+
3163+
ExternalTypeItem (ExternalTypeItem &&other) = default;
3164+
ExternalTypeItem &operator= (ExternalTypeItem &&other) = default;
3165+
3166+
std::string as_string () const override;
3167+
3168+
void accept_vis (HIRFullVisitor &vis) override;
3169+
void accept_vis (HIRExternalItemVisitor &vis) override;
3170+
3171+
ExternKind get_extern_kind () override { return ExternKind::Type; }
3172+
3173+
protected:
3174+
ExternalTypeItem *clone_external_item_impl () const override
3175+
{
3176+
return new ExternalTypeItem (*this);
3177+
}
3178+
};
3179+
31473180
// An extern block HIR node
31483181
class ExternBlock : public VisItem, public WithInnerAttrs
31493182
{

gcc/rust/hir/tree/rust-hir-visitor.h

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class HIRFullVisitor
114114
virtual void visit (ImplBlock &impl) = 0;
115115
virtual void visit (ExternalStaticItem &item) = 0;
116116
virtual void visit (ExternalFunctionItem &item) = 0;
117+
virtual void visit (ExternalTypeItem &item) = 0;
117118
virtual void visit (ExternBlock &block) = 0;
118119
virtual void visit (LiteralPattern &pattern) = 0;
119120
virtual void visit (IdentifierPattern &pattern) = 0;
@@ -255,6 +256,7 @@ class HIRFullVisitorBase : public HIRFullVisitor
255256

256257
virtual void visit (ExternalStaticItem &) override {}
257258
virtual void visit (ExternalFunctionItem &) override {}
259+
virtual void visit (ExternalTypeItem &) override {}
258260
virtual void visit (ExternBlock &) override {}
259261

260262
virtual void visit (LiteralPattern &) override {}
@@ -306,6 +308,7 @@ class HIRExternalItemVisitor
306308
public:
307309
virtual void visit (ExternalStaticItem &item) = 0;
308310
virtual void visit (ExternalFunctionItem &item) = 0;
311+
virtual void visit (ExternalTypeItem &item) = 0;
309312
};
310313

311314
class HIRTraitItemVisitor

gcc/rust/hir/tree/rust-hir.cc

+25
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,19 @@ ExternalFunctionItem::as_string () const
32563256
return str;
32573257
}
32583258

3259+
std::string
3260+
ExternalTypeItem::as_string () const
3261+
{
3262+
std::string str = ExternalItem::as_string ();
3263+
3264+
str += "type ";
3265+
3266+
// add name
3267+
str += get_item_name ().as_string ();
3268+
3269+
return str;
3270+
}
3271+
32593272
std::string
32603273
NamedFunctionParam::as_string () const
32613274
{
@@ -4272,6 +4285,12 @@ ExternalFunctionItem::accept_vis (HIRFullVisitor &vis)
42724285
vis.visit (*this);
42734286
}
42744287

4288+
void
4289+
ExternalTypeItem::accept_vis (HIRFullVisitor &vis)
4290+
{
4291+
vis.visit (*this);
4292+
}
4293+
42754294
void
42764295
ExternBlock::accept_vis (HIRFullVisitor &vis)
42774296
{
@@ -4542,6 +4561,12 @@ ExternalFunctionItem::accept_vis (HIRExternalItemVisitor &vis)
45424561
vis.visit (*this);
45434562
}
45444563

4564+
void
4565+
ExternalTypeItem::accept_vis (HIRExternalItemVisitor &vis)
4566+
{
4567+
vis.visit (*this);
4568+
}
4569+
45454570
void
45464571
ExternalStaticItem::accept_vis (HIRExternalItemVisitor &vis)
45474572
{

0 commit comments

Comments
 (0)