diff options
| author | John Hodge <tpg@mutabah.net> | 2016-08-29 16:07:28 +0800 |
|---|---|---|
| committer | John Hodge <tpg@mutabah.net> | 2016-08-29 16:07:28 +0800 |
| commit | 4c5e8ffbd413772859739e8cad57f925ba85dad8 (patch) | |
| tree | d22427268aeee7a91b88ee1746845d7a1b74032d /src/expand | |
| parent | a8da316a2646428acb780e889b322edf5f00549e (diff) | |
| download | mrust-4c5e8ffbd413772859739e8cad57f925ba85dad8.tar.gz | |
AST Resolve - Prelude handling
Diffstat (limited to 'src/expand')
| -rw-r--r-- | src/expand/mod.cpp | 8 | ||||
| -rw-r--r-- | src/expand/std_prelude.cpp | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index be7e17b0..2fc7b18a 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -567,6 +567,10 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo for( const auto& mi: mod.macro_imports_res() ) DEBUG("- Imports '" << mi.name << "'"); + if( mod.m_insert_prelude && crate.m_prelude_path != AST::Path() ) { + mod.add_alias(false, ::AST::UseStmt(Span(), crate.m_prelude_path), "", {}); + } + // TODO: Have the AST representation of a module include the definition order, // mixing macro invocations, general items, use statements, and `impl`s @@ -869,7 +873,7 @@ void Expand(::AST::Crate& crate) switch( crate.m_load_std ) { case ::AST::Crate::LOAD_STD: - if( crate.m_prelude_path != AST::Path() ) + if( crate.m_prelude_path == AST::Path() ) crate.m_prelude_path = AST::Path("std", {AST::PathNode("prelude"), AST::PathNode("v1")}); crate.load_extern_crate("std"); crate.m_extern_crates.at("std").with_all_macros([&](const auto& name, const auto& mac) { @@ -878,7 +882,7 @@ void Expand(::AST::Crate& crate) crate.m_root_module.add_ext_crate(false, "std", "std", ::AST::MetaItems {}); break; case ::AST::Crate::LOAD_CORE: - if( crate.m_prelude_path != AST::Path() ) + if( crate.m_prelude_path == AST::Path() ) crate.m_prelude_path = AST::Path("core", {AST::PathNode("prelude")}); crate.load_extern_crate("core"); crate.m_extern_crates.at("core").with_all_macros([&](const auto& name, const auto& mac) { diff --git a/src/expand/std_prelude.cpp b/src/expand/std_prelude.cpp index b7493570..a46740a7 100644 --- a/src/expand/std_prelude.cpp +++ b/src/expand/std_prelude.cpp @@ -41,6 +41,15 @@ class Decorator_NoPrelude: { public: AttrStage stage() const override { return AttrStage::EarlyPre; } + + void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + if( i.is_Module() ) { + i.as_Module().m_insert_prelude = false; + } + else { + ERROR(sp, E0000, "Invalid use of #[no_prelude] on non-module"); + } + } }; |
