summaryrefslogtreecommitdiff
path: root/src/mir
diff options
context:
space:
mode:
authorJohn Hodge (bugs) <tpg@mutabah.net>2017-03-04 18:12:49 +0800
committerJohn Hodge (bugs) <tpg@mutabah.net>2017-03-04 18:12:49 +0800
commitc6fca061dd134068c831aefd88d9535a30f423ed (patch)
tree28fc4abecddf8514792a4cb748f1c6e5700274c1 /src/mir
parent03addc877bab648ccde022edec29f5b051ce7cb9 (diff)
downloadmrust-c6fca061dd134068c831aefd88d9535a30f423ed.tar.gz
Many many changes to allow compiling in visual studio (Community 2015)
Diffstat (limited to 'src/mir')
-rw-r--r--src/mir/check.cpp13
-rw-r--r--src/mir/from_hir.cpp13
-rw-r--r--src/mir/from_hir.hpp2
-rw-r--r--src/mir/from_hir_match.cpp28
-rw-r--r--src/mir/helpers.hpp6
-rw-r--r--src/mir/mir.hpp2
-rw-r--r--src/mir/mir_builder.cpp6
7 files changed, 37 insertions, 33 deletions
diff --git a/src/mir/check.cpp b/src/mir/check.cpp
index 638a540c..807f08aa 100644
--- a/src/mir/check.cpp
+++ b/src/mir/check.cpp
@@ -725,7 +725,7 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
// TODO: Check suitability of source type (COMPLEX)
),
(BinOp,
- #if 0
+ /*
::HIR::TypeRef tmp_l, tmp_r;
const auto& ty_l = state.get_lvalue_type(tmp_l, e.val_l);
const auto& ty_r = state.get_lvalue_type(tmp_r, e.val_r);
@@ -740,7 +740,7 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
if( ty_l != ty_r )
MIR_BUG(state, "Type mismatch in binop, " << ty_l << " != " << ty_r);
}
- #endif
+ */
// TODO: Check return type
),
(UniOp,
@@ -757,8 +757,9 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
ity_p = &*ty.m_data.as_Borrow().inner;
else if( ty.m_data.is_Pointer() )
ity_p = &*ty.m_data.as_Pointer().inner;
- else
+ else {
MIR_BUG(state, "DstMeta requires a &-ptr as input, got " << ty);
+ }
const auto& ity = *ity_p;
if( ity.m_data.is_Generic() )
;
@@ -790,8 +791,9 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
ity_p = &*ty.m_data.as_Borrow().inner;
else if( ty.m_data.is_Pointer() )
ity_p = &*ty.m_data.as_Pointer().inner;
- else
+ else {
MIR_BUG(state, "DstPtr requires a &-ptr as input, got " << ty);
+ }
const auto& ity = *ity_p;
if( ity.m_data.is_Slice() )
;
@@ -817,8 +819,9 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
ity_p = &*te->inner;
else if( const auto* te = ty.m_data.opt_Pointer() )
ity_p = &*te->inner;
- else
+ else {
MIR_BUG(state, "DstMeta requires a pointer as output, got " << ty);
+ }
assert(ity_p);
auto meta = get_metadata_type(state, *ity_p);
if( meta == ::HIR::TypeRef() )
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 722e3aa1..e62722ef 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -884,19 +884,16 @@ namespace {
case _(Sub): op = ::MIR::eBinOp::SUB; if(0)
case _(Mul): op = ::MIR::eBinOp::MUL; if(0)
case _(Div): op = ::MIR::eBinOp::DIV; if(0)
- case _(Mod): op = ::MIR::eBinOp::MOD; if(0)
- ;
+ case _(Mod): op = ::MIR::eBinOp::MOD;
this->generate_checked_binop(sp, mv$(dst), op, mv$(dst_clone), ty_slot, mv$(val_lv), ty_val);
break;
case _(Xor): op = ::MIR::eBinOp::BIT_XOR; if(0)
case _(Or ): op = ::MIR::eBinOp::BIT_OR ; if(0)
- case _(And): op = ::MIR::eBinOp::BIT_AND; if(0)
- ;
+ case _(And): op = ::MIR::eBinOp::BIT_AND;
this->generate_checked_binop(sp, mv$(dst), op, mv$(dst_clone), ty_slot, mv$(val_lv), ty_val);
break;
case _(Shl): op = ::MIR::eBinOp::BIT_SHL; if(0)
- case _(Shr): op = ::MIR::eBinOp::BIT_SHR; if(0)
- ;
+ case _(Shr): op = ::MIR::eBinOp::BIT_SHR;
this->generate_checked_binop(sp, mv$(dst), op, mv$(dst_clone), ty_slot, mv$(val_lv), ty_val);
break;
}
@@ -1794,7 +1791,7 @@ namespace {
(Function,
// TODO: Why not use the result type?
//auto monomorph_cb = monomorphise_type_get_cb(sp, nullptr, nullptr, &pe.m_params);
- auto monomorph_cb = [&](const auto& gt)->const auto& {
+ auto monomorph_cb = [&](const auto& gt)->const ::HIR::TypeRef& {
const auto& e = gt.m_data.as_Generic();
if( e.binding == 0xFFFF ) {
BUG(sp, "Reference to Self in free function - " << gt);
@@ -1860,7 +1857,7 @@ namespace {
),
(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; },
+ auto rv = m_builder.crate().find_type_impls(*pe.type, [&](const auto& ty)->const ::HIR::TypeRef& { return ty; },
[&](const auto& impl) {
DEBUG("- impl" << impl.m_params.fmt_args() << " " << impl.m_type);
// Associated functions
diff --git a/src/mir/from_hir.hpp b/src/mir/from_hir.hpp
index c8d34151..1b57a7f4 100644
--- a/src/mir/from_hir.hpp
+++ b/src/mir/from_hir.hpp
@@ -51,7 +51,7 @@ TAGGED_UNION_EX(VarState, (), Invalid, (
// Partially valid (Map of field states, Box is assumed to have one field)
(Partial, struct {
::std::vector<VarState> inner_states;
- unsigned int outer_flag = ~0u; // If ~0u there's no condition on the outer
+ unsigned int outer_flag; // If ~0u there's no condition on the outer
}),
// Optionally valid (integer indicates the drop flag index)
(Optional, unsigned int),
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp
index e08cd5f7..aa9825cd 100644
--- a/src/mir/from_hir_match.cpp
+++ b/src/mir/from_hir_match.cpp
@@ -1733,7 +1733,7 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span&
),
(Array,
TODO(sp, "Match directly on array?");
- #if 0
+ /*
unsigned int total = 0;
for( unsigned int i = 0; i < te.size_val; i ++ ) {
unsigned int cnt = MIR_LowerHIR_Match_Simple__GeneratePattern(
@@ -1748,7 +1748,7 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span&
if( num_rules == 0 )
return total;
}
- #endif
+ */
),
(Slice,
ASSERT_BUG(sp, rule.is_Slice() || rule.is_SplitSlice() || (rule.is_Value() && rule.as_Value().is_Bytes()), "Can only match slice with Bytes or Slice rules - " << rule);
@@ -1933,7 +1933,7 @@ struct DecisionTreeNode
DecisionTreeNode clone() const;
void populate_tree_from_rule(const Span& sp, unsigned int arm_index, const PatternRule* first_rule, unsigned int rule_count) {
- populate_tree_from_rule(sp, first_rule, rule_count, [sp,arm_index](auto& branch){
+ populate_tree_from_rule(sp, first_rule, rule_count, [sp,arm_index](Branch& branch){
TU_MATCHA( (branch), (e),
(Unset,
// Good
@@ -2385,13 +2385,17 @@ void DecisionTreeNode::populate_tree_from_rule(const Span& sp, const PatternRule
ASSERT_BUG(sp, m_field_path == rule.field_path, "Patterns with mismatched field paths - " << m_field_path << " != " << rule.field_path);
}
- #define GET_BRANCHES(fld, var) (({if( fld.is_Unset() ) {\
- fld = Values::make_##var({}); \
- } \
- else if( !fld.is_##var() ) { \
- BUG(sp, "Mismatched rules - have " #var ", but have seen " << fld.tag_str()); \
- }}), \
- fld.as_##var())
+ struct GET_BRANCHES_H {
+ static void unexpected_type(const Span& sp, const char* exp, const char* have) {
+ BUG(sp, "Mismatched rules - have " << exp << ", but have seen " << have);
+ }
+ };
+ #define GET_BRANCHES(fld, var) (fld.is_Unset()\
+ ? (fld = Values::make_##var({})).as_##var() \
+ : (fld.is_##var() \
+ ? fld.as_##var() : (GET_BRANCHES_H::unexpected_type(sp, #var, fld.tag_str()), fld.as_##var()) \
+ )\
+ )
TU_MATCHA( (rule), (e),
@@ -2437,7 +2441,7 @@ void DecisionTreeNode::populate_tree_from_rule(const Span& sp, const PatternRule
if( e.sub_rules.size() > 0 && rule_count > 1 )
{
- subtree.populate_tree_from_rule(sp, e.sub_rules.data(), e.sub_rules.size(), [&](auto& branch){
+ subtree.populate_tree_from_rule(sp, e.sub_rules.data(), e.sub_rules.size(), [&](Branch& branch){
TU_MATCH_DEF(Branch, (branch), (be),
(
BUG(sp, "Duplicate terminator");
@@ -2482,7 +2486,7 @@ void DecisionTreeNode::populate_tree_from_rule(const Span& sp, const PatternRule
if( e.sub_rules.size() > 0 && rule_count > 1 )
{
- subtree.populate_tree_from_rule(sp, e.sub_rules.data(), e.sub_rules.size(), [&](auto& branch){
+ subtree.populate_tree_from_rule(sp, e.sub_rules.data(), e.sub_rules.size(), [&](Branch& branch){
TU_MATCH_DEF(Branch, (branch), (be),
(
BUG(sp, "Duplicate terminator");
diff --git a/src/mir/helpers.hpp b/src/mir/helpers.hpp
index e8f52651..c91e4198 100644
--- a/src/mir/helpers.hpp
+++ b/src/mir/helpers.hpp
@@ -13,8 +13,8 @@
namespace HIR {
class Crate;
class TypeRef;
-class Pattern;
-class SimplePath;
+struct Pattern;
+struct SimplePath;
}
namespace MIR {
@@ -22,7 +22,7 @@ namespace MIR {
class Function;
class LValue;
class Constant;
-class BasicBlock;
+struct BasicBlock;
typedef unsigned int BasicBlockId;
diff --git a/src/mir/mir.hpp b/src/mir/mir.hpp
index aed7e2fc..75bb29a8 100644
--- a/src/mir/mir.hpp
+++ b/src/mir/mir.hpp
@@ -262,7 +262,7 @@ TAGGED_UNION(Statement, Assign,
(SetDropFlag, struct {
unsigned int idx;
bool new_val; // If `other` is populated, this indicates that the other value should be negated
- unsigned int other = ~0u;
+ unsigned int other;
}),
// Drop a value
(Drop, struct {
diff --git a/src/mir/mir_builder.cpp b/src/mir/mir_builder.cpp
index aa42cbc1..296dfa91 100644
--- a/src/mir/mir_builder.cpp
+++ b/src/mir/mir_builder.cpp
@@ -190,7 +190,7 @@ void MirBuilder::define_variable(unsigned int idx)
{
auto temp = new_temporary(ty);
push_stmt_assign( sp, ::MIR::LValue(temp.clone()), mv$(rv) );
- return temp;
+ return ::MIR::Param( mv$(temp) );
}
}
void MirBuilder::set_result(const Span& sp, ::MIR::RValue val)
@@ -1627,10 +1627,10 @@ void MirBuilder::moved_lvalue(const Span& sp, const ::MIR::LValue& lv)
BUG(sp, "Box move out of invalid LValue " << inner_lv << " - should have been moved");
),
(Variable,
- get_variable_state_mut(sp, ei) = VarState::make_Partial({ mv$(ivs) });
+ get_variable_state_mut(sp, ei) = VarState::make_Partial({ mv$(ivs), ~0u });
),
(Temporary,
- get_temp_state_mut(sp, ei.idx) = VarState::make_Partial({ mv$(ivs) });
+ get_temp_state_mut(sp, ei.idx) = VarState::make_Partial({ mv$(ivs), ~0u });
),
(Argument,
TODO(sp, "Mark arg " << ei.idx << " for shallow drop");