diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/hir.cpp | 16 | ||||
-rw-r--r-- | src/hir/hir.hpp | 3 | ||||
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 2 | ||||
-rw-r--r-- | src/hir_typeck/expr_check.cpp | 3 | ||||
-rw-r--r-- | src/hir_typeck/expr_visit.cpp | 3 | ||||
-rw-r--r-- | src/mir/visit_crate_mir.cpp | 3 |
6 files changed, 23 insertions, 7 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 88b1cb8c..2e9b2830 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -188,6 +188,22 @@ uint32_t HIR::Enum::get_value(size_t idx) const throw ""; } } +/*static*/ ::HIR::TypeRef HIR::Enum::get_repr_type(Repr r) +{ + switch(r) + { + case ::HIR::Enum::Repr::Rust: + case ::HIR::Enum::Repr::C: + return ::HIR::CoreType::Isize; + break; + case ::HIR::Enum::Repr::Usize: return ::HIR::CoreType::Usize; break; + case ::HIR::Enum::Repr::U8 : return ::HIR::CoreType::U8 ; break; + case ::HIR::Enum::Repr::U16: return ::HIR::CoreType::U16; break; + case ::HIR::Enum::Repr::U32: return ::HIR::CoreType::U32; break; + case ::HIR::Enum::Repr::U64: return ::HIR::CoreType::U64; break; + } + throw ""; +} const ::HIR::SimplePath& ::HIR::Crate::get_lang_item_path(const Span& sp, const char* name) const diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index 8b718b4f..0188ba58 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -304,6 +304,9 @@ public: bool is_value() const; /// Returns the value for the given variant (onlu for value enums) uint32_t get_value(size_t variant) const; + + /// Get a type for the given repr value + static ::HIR::TypeRef get_repr_type(Repr r); }; class Struct { diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 35669dd9..47c6aaee 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -1172,7 +1172,7 @@ namespace { static Span sp; if( auto* e = item.m_data.opt_Value() ) { - ::HIR::TypeRef ty = ::HIR::CoreType::Isize; + auto ty = ::HIR::Enum::get_repr_type(e->repr); uint64_t i = 0; for(auto& var : e->variants) { diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index 7abe5532..7c9367e4 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -1325,8 +1325,7 @@ namespace { if( auto* e = item.m_data.opt_Value() ) { - // TODO: Use a different type depding on repr() - auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Isize); + auto enum_type = ::HIR::Enum::get_repr_type(e->repr); for(auto& var : e->variants) { DEBUG("Enum value " << p << " - " << var.name); diff --git a/src/hir_typeck/expr_visit.cpp b/src/hir_typeck/expr_visit.cpp index df27b7d7..ceb4110a 100644 --- a/src/hir_typeck/expr_visit.cpp +++ b/src/hir_typeck/expr_visit.cpp @@ -221,8 +221,7 @@ namespace { if( auto* e = item.m_data.opt_Value() ) { - // TODO: Use a different type depding on repr() - auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Isize); + auto enum_type = ::HIR::Enum::get_repr_type(e->repr); for(auto& var : e->variants) { diff --git a/src/mir/visit_crate_mir.cpp b/src/mir/visit_crate_mir.cpp index 79d2e32a..0bbf20ae 100644 --- a/src/mir/visit_crate_mir.cpp +++ b/src/mir/visit_crate_mir.cpp @@ -74,8 +74,7 @@ void MIR::OuterVisitor::visit_enum(::HIR::ItemPath p, ::HIR::Enum& item) if( auto* e = item.m_data.opt_Value() ) { - // TODO: Use a different type depding on repr() - auto enum_type = ::HIR::TypeRef(::HIR::CoreType::Isize); + auto enum_type = ::HIR::Enum::get_repr_type(e->repr); for(auto& var : e->variants) { |