summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/index.cpp39
-rw-r--r--src/resolve/use.cpp168
2 files changed, 113 insertions, 94 deletions
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index 6de86a2e..2890f247 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -231,28 +231,37 @@ void Resolve_Index_Module_Wildcard(AST::Module& mod, bool handle_pub)
),
(Module,
DEBUG("Glob mod " << i.data.path);
- if( e.module_ == &mod ) {
- ERROR(sp, E0000, "Glob import of self");
- }
- // 1. Begin indexing of this module if it is not already indexed
- if( e.module_->m_index_populated == 1 )
+ if( !e.module_ )
{
- // TODO: Handle wildcard import of a module with a public wildcard import
- TODO(sp, "Handle wildcard import of module with a wildcard (" << e.module_->path() << " by " << mod.path() << ")");
- //Resolve_Index_Module( *e.module_ );
+ ASSERT_BUG(sp, e.hir, "Glob import but module pointer not set - " << i.data.path);
+ TODO(sp, "Glob import from HIR module - " << i.data.path);
}
- for(const auto& vi : e.module_->m_type_items) {
- if( vi.second.is_pub ) {
- _add_item_type( sp, mod, vi.first, i.is_pub, vi.second.path, false );
+ else
+ {
+ if( e.module_ == &mod ) {
+ ERROR(sp, E0000, "Glob import of self");
}
- }
- for(const auto& vi : e.module_->m_value_items) {
- if( vi.second.is_pub ) {
- _add_item_value( sp, mod, vi.first, i.is_pub, vi.second.path, false );
+ // 1. Begin indexing of this module if it is not already indexed
+ if( e.module_->m_index_populated == 1 )
+ {
+ // TODO: Handle wildcard import of a module with a public wildcard import
+ TODO(sp, "Handle wildcard import of module with a wildcard (" << e.module_->path() << " by " << mod.path() << ")");
+ //Resolve_Index_Module( *e.module_ );
+ }
+ for(const auto& vi : e.module_->m_type_items) {
+ if( vi.second.is_pub ) {
+ _add_item_type( sp, mod, vi.first, i.is_pub, vi.second.path, false );
+ }
+ }
+ for(const auto& vi : e.module_->m_value_items) {
+ if( vi.second.is_pub ) {
+ _add_item_value( sp, mod, vi.first, i.is_pub, vi.second.path, false );
+ }
}
}
),
(Enum,
+ ASSERT_BUG(sp, e.enum_, "Glob import but enum pointer not set - " << i.data.path);
DEBUG("Glob enum " << i.data.path);
unsigned int idx = 0;
for( const auto& ev : e.enum_->variants() ) {
diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp
index 57679f8b..f977f0d1 100644
--- a/src/resolve/use.cpp
+++ b/src/resolve/use.cpp
@@ -302,8 +302,96 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
}
}
+::AST::PathBinding Resolve_Use_GetBinding__ext(const Span& span, const ::AST::Crate& crate, const ::AST::Path& path, const AST::ExternCrate& ec, unsigned int start)
+{
+ const auto& nodes = path.nodes();
+ const ::HIR::Module* hmod = &ec.m_hir->m_root_module;
+ for(unsigned int i = start; i < nodes.size() - 1; i ++)
+ {
+ auto it = hmod->m_mod_items.find(nodes[i].name());
+ if( it == hmod->m_mod_items.end() ) {
+ // BZZT!
+ ERROR(span, E0000, "Unable to find path component " << nodes[i].name() << " in " << path);
+ }
+ TU_MATCH_DEF( ::HIR::TypeItem, (it->second->ent), (e),
+ (
+ ERROR(span, E0000, "Unexpected item type in import");
+ ),
+ (Module,
+ hmod = &e;
+ ),
+ (Enum,
+ i += 1;
+ if( i != nodes.size() - 1 ) {
+ ERROR(span, E0000, "Encountered enum at unexpected location in import");
+ }
+ const auto& name = nodes[i].name();
+
+ auto it2 = ::std::find_if( e.m_variants.begin(), e.m_variants.end(), [&](const auto& x){ return x.first == name; } );
+ if( it2 == e.m_variants.end() ) {
+ ERROR(span, E0000, "Unable to find variant " << path);
+ }
+ return ::AST::PathBinding::make_EnumVar({ nullptr, static_cast<unsigned int>(it2 - e.m_variants.begin()) });
+ )
+ )
+ }
+ auto it = hmod->m_mod_items.find(nodes.back().name());
+ if( it != hmod->m_mod_items.end() ) {
+ TU_MATCHA( (it->second->ent), (e),
+ (Import,
+ TODO(span, "Recurse to get binding for an import");
+ ),
+ (Module,
+ return ::AST::PathBinding::make_Module({nullptr, &e});
+ ),
+ (TypeAlias,
+ return ::AST::PathBinding::make_TypeAlias({nullptr});
+ ),
+ (Enum,
+ return ::AST::PathBinding::make_Enum({nullptr});
+ ),
+ (Struct,
+ return ::AST::PathBinding::make_Struct({nullptr});
+ ),
+ (Trait,
+ return ::AST::PathBinding::make_Trait({nullptr});
+ )
+ )
+ }
+ auto it2 = hmod->m_value_items.find(nodes.back().name());
+ if( it2 != hmod->m_value_items.end() ) {
+ TU_MATCHA( (it2->second->ent), (e),
+ (Import,
+ TODO(span, "Recurse to get binding for an import");
+ ),
+ (Constant,
+ return ::AST::PathBinding::make_Static({ nullptr });
+ ),
+ (Static,
+ return ::AST::PathBinding::make_Static({ nullptr });
+ ),
+ (StructConstant,
+ return ::AST::PathBinding::make_Struct({ nullptr });
+ ),
+ (Function,
+ return ::AST::PathBinding::make_Function({ nullptr });
+ ),
+ (StructConstructor,
+ return ::AST::PathBinding::make_Struct({ nullptr });
+ )
+ )
+ }
+
+ TODO(span, "Get binding within an extern crate");
+}
+
::AST::PathBinding Resolve_Use_GetBinding(const Span& span, const ::AST::Crate& crate, const ::AST::Path& path, slice< const ::AST::Module* > parent_modules)
{
+ if( path.m_class.is_Absolute() && path.m_class.as_Absolute().crate != "" ) {
+ const auto& path_abs = path.m_class.as_Absolute();
+
+ return Resolve_Use_GetBinding__ext(span, crate, path, crate.m_extern_crates.at( path_abs.crate ), 0);
+ }
const AST::Module* mod = &crate.m_root_module;
const auto& nodes = path.nodes();
for( unsigned int i = 0; i < nodes.size()-1; i ++ )
@@ -314,85 +402,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
ERROR(span, E0000, "Unexpected item type in import");
),
(Crate,
- const ::HIR::Module* hmod = &e.crate_->m_hir->m_root_module;
- i ++;
- for(; i < nodes.size() - 1; i ++)
- {
- auto it = hmod->m_mod_items.find(nodes[i].name());
- if( it == hmod->m_mod_items.end() ) {
- // BZZT!
- ERROR(span, E0000, "Unable to find path component " << nodes[i].name() << " in " << path);
- }
- TU_MATCH_DEF( ::HIR::TypeItem, (it->second->ent), (e),
- (
- ERROR(span, E0000, "Unexpected item type in import");
- ),
- (Module,
- hmod = &e;
- ),
- (Enum,
- i += 1;
- if( i != nodes.size() - 1 ) {
- ERROR(span, E0000, "Encountered enum at unexpected location in import");
- }
- const auto& name = nodes[i].name();
-
- auto it2 = ::std::find_if( e.m_variants.begin(), e.m_variants.end(), [&](const auto& x){ return x.first == name; } );
- if( it2 == e.m_variants.end() ) {
- ERROR(span, E0000, "Unable to find variant " << path);
- }
- return ::AST::PathBinding::make_EnumVar({ nullptr, static_cast<unsigned int>(it2 - e.m_variants.begin()) });
- )
- )
- }
- auto it = hmod->m_mod_items.find(nodes[i].name());
- if( it != hmod->m_mod_items.end() ) {
- TU_MATCHA( (it->second->ent), (e),
- (Import,
- TODO(span, "Recurse to get binding for an import");
- ),
- (Module,
- return ::AST::PathBinding::make_Module({nullptr, &e});
- ),
- (TypeAlias,
- return ::AST::PathBinding::make_TypeAlias({nullptr});
- ),
- (Enum,
- return ::AST::PathBinding::make_Enum({nullptr});
- ),
- (Struct,
- return ::AST::PathBinding::make_Struct({nullptr});
- ),
- (Trait,
- return ::AST::PathBinding::make_Trait({nullptr});
- )
- )
- }
- auto it2 = hmod->m_value_items.find(nodes[i].name());
- if( it2 != hmod->m_value_items.end() ) {
- TU_MATCHA( (it2->second->ent), (e),
- (Import,
- TODO(span, "Recurse to get binding for an import");
- ),
- (Constant,
- return ::AST::PathBinding::make_Static({ nullptr });
- ),
- (Static,
- return ::AST::PathBinding::make_Static({ nullptr });
- ),
- (StructConstant,
- return ::AST::PathBinding::make_Struct({ nullptr });
- ),
- (Function,
- return ::AST::PathBinding::make_Function({ nullptr });
- ),
- (StructConstructor,
- return ::AST::PathBinding::make_Struct({ nullptr });
- )
- )
- }
-
- TODO(span, "Get binding within an extern crate");
+ return Resolve_Use_GetBinding__ext(span, crate, path, *e.crate_, i+1);
),
(Enum,
const auto& enum_ = *e.enum_;