diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-29 12:07:55 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-29 12:07:55 +0800 |
commit | d8fed3a1def1ae667c1471f44b19749a1f88cc42 (patch) | |
tree | 3fe49e5d8c8aef99c53b9b6b9bf2e5914145db95 | |
parent | 0c3cd458773f2fa416dbb3448b0976e1ab178476 (diff) | |
download | mrust-d8fed3a1def1ae667c1471f44b19749a1f88cc42.tar.gz |
HIR Const Eval - Rough associated constant lookup
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 727031d2..b362d5f9 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -193,10 +193,41 @@ namespace { return rv; ), (UfcsKnown, - TODO(sp, "get_ent_fullpath(path = " << path << ")"); + EntPtr rv; + crate.find_trait_impls(e.trait.m_path, *e.type, [](const auto&x)->const auto& { return x; }, [&](const auto& impl) { + // Hacky selection of impl. + // - TODO: Specialisation + // - TODO: Inference? (requires full typeck) + switch( ns ) + { + case EntNS::Value: + { + auto fit = impl.m_methods.find(e.item); + if( fit != impl.m_methods.end() ) + { + DEBUG("Found impl" << impl.m_params.fmt_args() << " " << impl.m_type); + rv = EntPtr { &fit->second.data }; + return true; + } + } + { + auto it = impl.m_constants.find(e.item); + if( it != impl.m_constants.end() ) + { + rv = EntPtr { &it->second.data }; + return true; + } + } + break; + case EntNS::Type: + break; + } + return false; + }); + return rv; ), (UfcsUnknown, - // TODO - Since this isn't known, can it be searched properly? + // TODO: Are these valid at this point in compilation? TODO(sp, "get_ent_fullpath(path = " << path << ")"); ) ) |