diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
commit | 1d2fe7681219700998c8ecbdb8ed5acab66578df (patch) | |
tree | 0d38e8ab5fd80c890d3dec67a0596abfc7a4f0cd /src/hir/hir.cpp | |
parent | c6fca061dd134068c831aefd88d9535a30f423ed (diff) | |
parent | fde22b3f03d802231985b8ded567cba16cb5aa00 (diff) | |
download | mrust-1d2fe7681219700998c8ecbdb8ed5acab66578df.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
# Conflicts:
# src/common.hpp
# src/hir/deserialise.cpp
# src/hir_typeck/static.cpp
# src/mir/from_hir.cpp
# src/mir/from_hir.hpp
# src/mir/from_hir_match.cpp
# src/mir/helpers.hpp
# src/mir/mir_builder.cpp
Diffstat (limited to 'src/hir/hir.cpp')
-rw-r--r-- | src/hir/hir.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 9d1fcf97..d50c3e49 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -93,6 +93,30 @@ const ::HIR::Enum::Variant* ::HIR::Enum::get_variant(const ::std::string& name) return nullptr; return &it->second; } +bool HIR::Enum::is_value() const +{ + return this->m_repr != ::HIR::Enum::Repr::Rust || ::std::all_of(m_variants.begin(), m_variants.end(), [](const auto& x){return x.second.is_Unit() || x.second.is_Value();}); +} +uint32_t HIR::Enum::get_value(size_t idx) const +{ + assert(idx < m_variants.size()); + + if( const auto* e = m_variants[idx].second.opt_Value() ) + { + return e->val.as_Integer(); + } + + uint32_t val = 0; + for(size_t i = 0; i < idx; i ++) + { + if( const auto* e = m_variants[i].second.opt_Value() ) + { + val = e->val.as_Integer(); + } + val ++; + } + return val; +} namespace { bool matches_genericpath(const ::HIR::GenericParams& params, const ::HIR::GenericPath& left, const ::HIR::GenericPath& right, ::HIR::t_cb_resolve_type ty_res, bool expand_generic); |