summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-23 14:17:15 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-23 14:17:15 +0800
commit77e307370c31c6246ec7e779b97d99e1ed387c07 (patch)
tree363cc79b298e014d8352b9a5aadb6b3e68155597 /src
parentd55492636278d1da58c845610d8427744f8b49a3 (diff)
downloadmrust-77e307370c31c6246ec7e779b97d99e1ed387c07.tar.gz
MIR Gen - Field access with_val_type
Diffstat (limited to 'src')
-rw-r--r--src/mir/mir_builder.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/mir/mir_builder.cpp b/src/mir/mir_builder.cpp
index 61e70a5a..5ed178dc 100644
--- a/src/mir/mir_builder.cpp
+++ b/src/mir/mir_builder.cpp
@@ -565,7 +565,8 @@ void MirBuilder::with_val_type(const ::MIR::LValue& val, ::std::function<void(co
TODO(sp, "Argument");
),
(Static,
- TODO(sp, "Static");
+ TODO(sp, "Static - " << e);
+ // TODO: Having a reference to the relevant static would be useful.
),
(Return,
TODO(sp, "Return");
@@ -577,7 +578,35 @@ void MirBuilder::with_val_type(const ::MIR::LValue& val, ::std::function<void(co
BUG(sp, "Field access on unexpected type - " << ty);
),
(Path,
- TODO(sp, "Field - Path");
+ ASSERT_BUG(sp, te.binding.is_Struct(), "Field on non-Struct - " << ty);
+ const auto& str = *te.binding.as_Struct();
+ TU_MATCHA( (str.m_data), (se),
+ (Unit,
+ BUG(sp, "Field on unit-like struct - " << ty);
+ ),
+ (Tuple,
+ ASSERT_BUG(sp, e.field_index < se.size(), "");
+ const auto& fld = se[e.field_index];
+ if( monomorphise_type_needed(fld.ent) ) {
+ auto sty = monomorphise_type(sp, str.m_params, te.path.m_data.as_Generic().m_params, fld.ent);
+ cb(sty);
+ }
+ else {
+ cb(fld.ent);
+ }
+ ),
+ (Named,
+ ASSERT_BUG(sp, e.field_index < se.size(), "");
+ const auto& fld = se[e.field_index].second;
+ if( monomorphise_type_needed(fld.ent) ) {
+ auto sty = monomorphise_type(sp, str.m_params, te.path.m_data.as_Generic().m_params, fld.ent);
+ cb(sty);
+ }
+ else {
+ cb(fld.ent);
+ }
+ )
+ )
),
(Tuple,
assert( e.field_index < te.size() );