aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2021-08-12 13:44:55 +0200
committerMarc <dkm@kataplop.net>2021-08-18 22:59:43 +0200
commitfd1d9c1af7c7afa43ebac162f9427420ea2314ff (patch)
tree9558f576df838d85451cad8a3b5c6ad4105c1438 /gcc
parent37a6b4ae78070b136d86bb0a7f207b8c2af69383 (diff)
downloadgcc-fd1d9c1af7c7afa43ebac162f9427420ea2314ff.zip
gcc-fd1d9c1af7c7afa43ebac162f9427420ea2314ff.tar.gz
gcc-fd1d9c1af7c7afa43ebac162f9427420ea2314ff.tar.bz2
hir: lower Module
Lower AST::Module to HIR::ModuleBodied. Add HIR::ModuleBodied::get_items to access module's items. Fix tests that are already using module. ref #432
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h38
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h2
-rw-r--r--gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks.rs10
-rw-r--r--gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks_crlf.rs11
4 files changed, 52 insertions, 9 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index 3083554..bcf83ee 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -29,6 +29,7 @@
#include "rust-ast-lower-pattern.h"
#include "rust-ast-lower-block.h"
#include "rust-ast-lower-extern.h"
+#include "rust-hir-full-decls.h"
namespace Rust {
namespace HIR {
@@ -54,6 +55,43 @@ public:
return resolver.translated;
}
+ void visit (AST::Module &module) override
+ {
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, module.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ // should be lowered from module.get_vis()
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+
+ auto items = std::vector<std::unique_ptr<Item> > ();
+
+ for (auto &item : module.get_items ())
+ {
+ auto transitem = translate (item.get ());
+ items.push_back (std::unique_ptr<Item> (transitem));
+ }
+
+ // should be lowered/copied from module.get_in/outer_attrs()
+ AST::AttrVec inner_attrs;
+ AST::AttrVec outer_attrs;
+
+ translated
+ = new HIR::ModuleBodied (mapping, module.get_name (), module.get_locus (),
+ std::move (items), std::move (vis),
+ std::move (inner_attrs),
+ std::move (outer_attrs));
+
+ mappings->insert_defid_mapping (mapping.get_defid (), translated);
+ mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (),
+ translated);
+ mappings->insert_module (mapping.get_crate_num (), mapping.get_hirid (),
+ static_cast<Module *> (translated));
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ module.get_locus ());
+ }
+
void visit (AST::TypeAlias &alias) override
{
std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index ba04339..32ee317 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -718,6 +718,8 @@ public:
void accept_vis (HIRVisitor &vis) override;
+ std::vector<std::unique_ptr<Item> > &get_items () { return items; };
+
/* Override that runs the function recursively on all items contained within
* the module. */
void add_crate_name (std::vector<std::string> &names) const override;
diff --git a/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks.rs b/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks.rs
index ab38ac6..41c3b51 100644
--- a/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks.rs
+++ b/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks.rs
@@ -9,7 +9,7 @@
/// outer doc line for module
/** outer doc block for module */
-pub mod module
+pub mod module // { dg-warning "unused name" }
{
//! inner line doc
//!! inner line doc!
@@ -24,21 +24,23 @@ pub mod module
/** outer block doc */
/*** block comment */
- mod block_doc_comments
+ mod block_doc_comments // { dg-warning "unused name" }
{
/* /* */ /** */ /*! */ */
/*! /* */ /** */ /*! */ */
/** /* */ /** */ /*! */ */
- mod item { }
+ mod item { } // { dg-warning "unused name" }
}
- pub mod empty
+ pub mod empty // { dg-warning "unused name" }
{
//!
/*!*/
//
///
+ // the following warning is issued one line earlier
+ // { dg-warning "unused name" }
mod doc { }
/**/
/***/
diff --git a/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks_crlf.rs b/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks_crlf.rs
index 3ea2cd0..e5ed911 100644
--- a/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks_crlf.rs
+++ b/gcc/testsuite/rust/compile/torture/all_doc_comment_line_blocks_crlf.rs
@@ -9,7 +9,7 @@
/// outer doc line for module
/** outer doc block for module */
-pub mod module
+pub mod module // { dg-warning "unused name" }
{
//! inner line doc
//!! inner line doc!
@@ -24,22 +24,23 @@ pub mod module
/** outer block doc */
/*** block comment */
- mod block_doc_comments
+ mod block_doc_comments // { dg-warning "unused name" }
{
/* /* */ /** */ /*! */ */
/*! /* */ /** */ /*! */ */
/** /* */ /** */ /*! */ */
- mod item { }
+ mod item { } // { dg-warning "unused name" }
}
- pub mod empty
+ pub mod empty // { dg-warning "unused name" }
{
//!
/*!*/
//
///
- mod doc { }
+ mod doc { } // { dg-warning "unused name" }
+
/**/
/***/
}