From 72366722bcda90960f18d108cf2d523d4e7f0cd8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 4 Nov 2016 10:30:20 +0800 Subject: HIR Annotate - Only borrow struct cosntructor base values when no fields are moved --- src/hir/hir.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/hir/hir.cpp') diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 3a8ab95b..5177f101 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -8,6 +8,7 @@ * HIR type helper code */ #include "hir.hpp" +#include namespace HIR { ::std::ostream& operator<<(::std::ostream& os, const ::HIR::Literal& v) @@ -45,6 +46,14 @@ namespace HIR { } } +const ::HIR::Enum::Variant* ::HIR::Enum::get_variant(const ::std::string& name) const +{ + auto it = ::std::find_if(m_variants.begin(), m_variants.end(), [&](const auto& x){ return x.first == name; }); + if( it == m_variants.end() ) + return nullptr; + return &it->second; +} + 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); -- cgit v1.2.3