summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-29 12:07:55 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-29 12:07:55 +0800
commitd8fed3a1def1ae667c1471f44b19749a1f88cc42 (patch)
tree3fe49e5d8c8aef99c53b9b6b9bf2e5914145db95
parent0c3cd458773f2fa416dbb3448b0976e1ab178476 (diff)
downloadmrust-d8fed3a1def1ae667c1471f44b19749a1f88cc42.tar.gz
HIR Const Eval - Rough associated constant lookup
-rw-r--r--src/hir_conv/constant_evaluation.cpp35
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 << ")");
)
)