diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-23 19:19:42 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-23 19:19:42 +0800 |
commit | 125122473e95db87df50be04b9bfd81874c65222 (patch) | |
tree | f23e346d802c447699d584939c180ff97bc251f3 | |
parent | 4753c7fef99fdf2f483c331a1c6bc62b8813bb7e (diff) | |
download | mrust-125122473e95db87df50be04b9bfd81874c65222.tar.gz |
MIR Gen - Emit code for PathValue pointing to a UfcsInherent
-rw-r--r-- | src/mir/from_hir.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index de90d789..fd0de5a2 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1223,7 +1223,25 @@ namespace { BUG(sp, "PathValue - Encountered UfcsUnknown - " << node.m_path); ), (UfcsInherent, - TODO(sp, "PathValue - UfcsInherent"); + // 1. Find item in an impl block + auto rv = m_builder.crate().find_type_impls(*pe.type, [&](const auto& ty)->const auto& { return ty; }, + [&](const auto& impl) { + DEBUG("- impl" << impl.m_params.fmt_args() << " " << impl.m_type); + auto it = impl.m_methods.find(pe.item); + if( it != impl.m_methods.end() ) { + // Function! + auto tmp = m_builder.new_temporary( node.m_res_type ); + m_builder.push_stmt_assign( sp, tmp.clone(), ::MIR::Constant::make_ItemAddr(node.m_path.clone()) ); + m_builder.set_result( sp, mv$(tmp) ); + return true; + } + // Associated consts (unimpl) + // Associated static (undef) + return false; + }); + if( !rv ) { + ERROR(sp, E0000, "Failed to locate item for " << node.m_path); + } ) ) } |