Skip to content

Commit ec0c3ad

Browse files
dkmphilberty
authored andcommitted
gccrs: refactor: make crate.items private
Introduce Crate::get_items () and fixup all callers. gcc/rust/ChangeLog: * hir/tree/rust-hir.h (struct Crate): Rename struct into ... (class Crate): ... class, and add get_items. * backend/rust-compile.cc (CompileCrate::go): Adapt to visibility change of items. * checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::go): Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::go): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::go): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::go): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::go): Likewise. * checks/lints/rust-lint-marklive.cc (FindEntryPoint::find): Likewise. * checks/lints/rust-lint-scan-deadcode.h (ScanDeadCode::Scan): Likewise. * metadata/rust-export-metadata.cc (PublicInterface::gather_export_data): Likewise. * typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): Likewise. * hir/rust-hir-dump.cc (CompileCrate::go): Likewise. Signed-off-by: Marc Poulhiès <[email protected]>
1 parent f044da1 commit ec0c3ad

13 files changed

+19
-24
lines changed

gcc/rust/backend/rust-compile.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ CompileCrate::Compile (HIR::Crate &crate, Context *ctx)
4343
void
4444
CompileCrate::go ()
4545
{
46-
for (auto &item : crate.items)
46+
for (auto &item : crate.get_items ())
4747
CompileItem::compile (item.get (), ctx);
4848
}
4949

gcc/rust/checks/errors/privacy/rust-privacy-check.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ Resolver::resolve (HIR::Crate &crate)
4545

4646
auto visitor = ReachabilityVisitor (ctx, *ty_ctx);
4747

48-
const auto &items = crate.items;
49-
50-
for (auto &item : items)
48+
for (auto &item : crate.get_items ())
5149
{
5250
if (item->get_hir_kind () == HIR::Node::VIS_ITEM)
5351
{

gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PrivacyReporter::PrivacyReporter (
3434
void
3535
PrivacyReporter::go (HIR::Crate &crate)
3636
{
37-
for (auto &item : crate.items)
37+
for (auto &item : crate.get_items ())
3838
item->accept_vis (*this);
3939
}
4040

gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ PubRestrictedVisitor::go (HIR::Crate &crate)
5757
// FIXME: When do we insert `super`? `self`?
5858
// We need wrapper function for these
5959

60-
for (auto &item : crate.items)
60+
for (auto &item : crate.get_items ())
6161
{
6262
if (item->get_hir_kind () == HIR::Node::VIS_ITEM)
6363
{

gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ VisibilityResolver::go (HIR::Crate &crate)
3737

3838
current_module = crate.get_mappings ().get_defid ();
3939

40-
for (auto &item : crate.items)
40+
for (auto &item : crate.get_items ())
4141
{
4242
if (item->get_hir_kind () == HIR::Node::VIS_ITEM)
4343
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ConstChecker::ConstChecker ()
3333
void
3434
ConstChecker::go (HIR::Crate &crate)
3535
{
36-
for (auto &item : crate.items)
36+
for (auto &item : crate.get_items ())
3737
item->accept_vis (*this);
3838
}
3939

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ UnsafeChecker::UnsafeChecker ()
3434
void
3535
UnsafeChecker::go (HIR::Crate &crate)
3636
{
37-
for (auto &item : crate.items)
37+
for (auto &item : crate.get_items ())
3838
item->accept_vis (*this);
3939
}
4040

gcc/rust/checks/lints/rust-lint-marklive.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ class FindEntryPoint : public MarkLiveBase
4141
static std::vector<HirId> find (HIR::Crate &crate)
4242
{
4343
FindEntryPoint findEntryPoint;
44-
for (auto it = crate.items.begin (); it != crate.items.end (); it++)
45-
{
46-
it->get ()->accept_vis (findEntryPoint);
47-
}
44+
for (auto &it : crate.get_items ())
45+
it->accept_vis (findEntryPoint);
4846
return findEntryPoint.getEntryPoint ();
4947
}
5048

gcc/rust/checks/lints/rust-lint-scan-deadcode.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ class ScanDeadcode : public MarkLiveBase
4444
{
4545
std::set<HirId> live_symbols = Analysis::MarkLive::Analysis (crate);
4646
ScanDeadcode sdc (live_symbols);
47-
for (auto it = crate.items.begin (); it != crate.items.end (); it++)
48-
{
49-
it->get ()->accept_vis (sdc);
50-
}
47+
for (auto &it : crate.get_items ())
48+
it.get ()->accept_vis (sdc);
5149
};
5250

5351
void visit (HIR::Function &function) override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Dump::go (HIR::Crate &crate)
4646
stream << "items: [";
4747

4848
stream << indentation;
49-
for (const auto &item : crate.items)
49+
for (const auto &item : crate.get_items ())
5050
{
5151
stream << std::endl;
5252
item->accept_vis (*this);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,18 +863,18 @@ class ImplItem : public Node, public FullVisitable
863863
};
864864

865865
// A crate HIR object - holds all the data for a single compilation unit
866-
struct Crate : public WithInnerAttrs
866+
class Crate : public WithInnerAttrs
867867
{
868868
// dodgy spacing required here
869869
/* TODO: is it better to have a vector of items here or a module (implicit
870870
* top-level one)? */
871-
std::vector<std::unique_ptr<Item> > items;
871+
std::vector<std::unique_ptr<Item>> items;
872872

873873
Analysis::NodeMapping mappings;
874874

875875
public:
876876
// Constructor
877-
Crate (std::vector<std::unique_ptr<Item> > items, AST::AttrVec inner_attrs,
877+
Crate (std::vector<std::unique_ptr<Item>> items, AST::AttrVec inner_attrs,
878878
Analysis::NodeMapping mappings)
879879
: WithInnerAttrs (std::move (inner_attrs)), items (std::move (items)),
880880
mappings (mappings)
@@ -912,6 +912,7 @@ struct Crate : public WithInnerAttrs
912912
std::string as_string () const;
913913

914914
const Analysis::NodeMapping &get_mappings () const { return mappings; }
915+
std::vector<std::unique_ptr<Item>> &get_items () { return items; }
915916
};
916917

917918
// Base path expression HIR node - abstract

gcc/rust/metadata/rust-export-metadata.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void
220220
PublicInterface::gather_export_data ()
221221
{
222222
ExportVisItems visitor (context);
223-
for (auto &item : crate.items)
223+
for (auto &item : crate.get_items ())
224224
{
225225
bool is_vis_item = item->get_hir_kind () == HIR::Node::BaseKind::VIS_ITEM;
226226
if (!is_vis_item)

gcc/rust/typecheck/rust-hir-type-check.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace Resolver {
3333
void
3434
TypeResolution::Resolve (HIR::Crate &crate)
3535
{
36-
for (auto it = crate.items.begin (); it != crate.items.end (); it++)
37-
TypeCheckItem::Resolve (*it->get ());
36+
for (auto &it : crate.get_items ())
37+
TypeCheckItem::Resolve (*it);
3838

3939
if (saw_errors ())
4040
return;

0 commit comments

Comments
 (0)