summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-12-28 19:58:29 +0800
committerJohn Hodge <tpg@mutabah.net>2018-12-28 19:58:29 +0800
commitb6fb5429b0983d5571c5ec01abbd502526ed9086 (patch)
tree18f4003b59c40d8575ee56c97ae5e855f4844d3d /src/resolve
parente16796df604ba1017a19917ea94840ee8c4b0336 (diff)
downloadmrust-b6fb5429b0983d5571c5ec01abbd502526ed9086.tar.gz
Resovle - Macro imports (partial), bugfixes
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/index.cpp19
-rw-r--r--src/resolve/use.cpp28
2 files changed, 41 insertions, 6 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index 148bf069..bbcd7e58 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -59,6 +59,7 @@ namespace {
void _add_item(const Span& sp, AST::Module& mod, IndexName location, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
{
+ ASSERT_BUG(sp, ir.m_bindings.has_binding(), "");
auto& list = get_mod_index(mod, location);
bool was_import = (ir != mod.path() + name);
@@ -262,16 +263,28 @@ void Resolve_Index_Module_Wildcard__glob_in_hir_mod(const Span& sp, const AST::C
for(const auto& it : hmod.m_mod_items) {
const auto& ve = *it.second;
if( ve.is_public ) {
+ const auto* vep = &ve.ent;
AST::Path p;
- if( ve.ent.is_Import() ) {
- p = hir_to_ast( ve.ent.as_Import().path );
+ if( vep->is_Import() ) {
+ const auto& spath = vep->as_Import().path;
+ p = hir_to_ast( spath );
+
+ ASSERT_BUG(sp, crate.m_extern_crates.count(spath.m_crate_name) == 1, "Crate " << spath.m_crate_name << " is not loaded");
+ const auto* hmod = &crate.m_extern_crates.at(spath.m_crate_name).m_hir->m_root_module;
+ for(unsigned int i = 0; i < spath.m_components.size()-1; i ++) {
+ const auto& it = hmod->m_mod_items.at( spath.m_components[i] );
+ ASSERT_BUG(sp, it->ent.is_Module(), "");
+ hmod = &it->ent.as_Module();
+ }
+ vep = &hmod->m_mod_items.at( spath.m_components.back() )->ent;
}
else {
p = path + it.first;
}
- TU_MATCHA( (ve.ent), (e),
+ TU_MATCHA( (*vep), (e),
(Import,
//throw "";
+ TODO(sp, "Get binding for HIR import? " << e.path);
),
(Module,
p.m_bindings.type = ::AST::PathBinding_Type::make_Module({nullptr, &e});
diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp
index a0d1aa53..203256a4 100644
--- a/src/resolve/use.cpp
+++ b/src/resolve/use.cpp
@@ -307,6 +307,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
rv.value = ::AST::PathBinding_Value::make_Static({&e});
),
(Struct,
+ // TODO: What happens with name collisions?
if( !e.m_data.is_Struct() )
rv.value = ::AST::PathBinding_Value::make_Struct({&e});
rv.type = ::AST::PathBinding_Type::make_Struct({&e});
@@ -321,9 +322,19 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
rv.type = ::AST::PathBinding_Type::make_Module({&e});
)
)
- return rv;
}
}
+ // TODO: macros
+ for(const auto& mac : mod.macros())
+ {
+ if( mac.name == des_item_name ) {
+ TODO(span, "Import of macro - " << des_item_name);
+ }
+ }
+ if( rv.has_binding() )
+ {
+ return rv;
+ }
// Imports
for( const auto& imp : mod.items() )
@@ -690,7 +701,17 @@ namespace {
}
::AST::Path::Bindings Resolve_Use_GetBinding__ext(const Span& span, const ::AST::Crate& crate, const ::AST::Path& path, const AST::ExternCrate& ec, unsigned int start)
{
- return Resolve_Use_GetBinding__ext(span, crate, path, ec.m_hir->m_root_module, start);
+ auto rv = Resolve_Use_GetBinding__ext(span, crate, path, ec.m_hir->m_root_module, start);
+ if( start + 1 == path.nodes().size() )
+ {
+ const auto& name = path.nodes().back().name();
+ auto it = ec.m_hir->m_exported_macros.find( name );
+ if( it != ec.m_hir->m_exported_macros.end() )
+ {
+ rv.macro = ::AST::PathBinding_Macro::make_MacroRules({ &ec, &*it->second });
+ }
+ }
+ return rv;
}
::AST::Path::Bindings Resolve_Use_GetBinding(const Span& span, const ::AST::Crate& crate, const ::AST::Path& path, ::std::span< const ::AST::Module* > parent_modules)
@@ -747,7 +768,7 @@ namespace {
{
if( enum_.variants()[j].m_name == node2.name() ) {
variant_index = j;
- is_value = !enum_.variants()[i].m_data.is_Struct();
+ is_value = !enum_.variants()[j].m_data.is_Struct();
break ;
}
}
@@ -755,6 +776,7 @@ namespace {
ERROR(span, E0000, "Unknown enum variant '" << node2.name() << "'");
}
+ DEBUG("AST Enum variant - " << variant_index << ", is_value=" << is_value << " " << enum_.variants()[variant_index].m_data.tag_str());
if( is_value ) {
rv.value = ::AST::PathBinding_Value::make_EnumVar({&enum_, static_cast<unsigned int>(variant_index)});
}