summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir_typeck/static.cpp19
-rw-r--r--src/hir_typeck/static.hpp4
-rw-r--r--src/mir/helpers.cpp23
-rw-r--r--src/trans/codegen_c.cpp10
4 files changed, 28 insertions, 28 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index f60414b2..b9a302a6 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -1363,3 +1363,22 @@ bool StaticTraitResolve::type_is_sized(const Span& sp, const ::HIR::TypeRef& ty)
)
throw "";
}
+
+const ::HIR::TypeRef* StaticTraitResolve::is_type_owned_box(const ::HIR::TypeRef& ty) const
+{
+ if( ! ty.m_data.is_Path() ) {
+ return nullptr;
+ }
+ const auto& te = ty.m_data.as_Path();
+
+ if( ! te.path.m_data.is_Generic() ) {
+ return nullptr;
+ }
+ const auto& pe = te.path.m_data.as_Generic();
+
+ if( pe.m_path != m_lang_Box ) {
+ return nullptr;
+ }
+ // TODO: Properly assert?
+ return &pe.m_params.m_types.at(0);
+}
diff --git a/src/hir_typeck/static.hpp b/src/hir_typeck/static.hpp
index b2b259fd..dd35df15 100644
--- a/src/hir_typeck/static.hpp
+++ b/src/hir_typeck/static.hpp
@@ -27,6 +27,7 @@ private:
::HIR::SimplePath m_lang_Fn;
::HIR::SimplePath m_lang_FnMut;
::HIR::SimplePath m_lang_FnOnce;
+ ::HIR::SimplePath m_lang_Box;
public:
StaticTraitResolve(const ::HIR::Crate& crate):
@@ -39,6 +40,7 @@ public:
m_lang_Fn = m_crate.get_lang_item_path_opt("fn");
m_lang_FnMut = m_crate.get_lang_item_path_opt("fn_mut");
m_lang_FnOnce = m_crate.get_lang_item_path_opt("fn_once");
+ m_lang_Box = m_crate.get_lang_item_path_opt("owned_box");
prep_indexes();
}
@@ -166,5 +168,7 @@ public:
// -------------
bool type_is_copy(const Span& sp, const ::HIR::TypeRef& ty) const;
bool type_is_sized(const Span& sp, const ::HIR::TypeRef& ty) const;
+
+ const ::HIR::TypeRef* is_type_owned_box(const ::HIR::TypeRef& ty) const;
};
diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp
index ba4f4ca1..6842ab72 100644
--- a/src/mir/helpers.cpp
+++ b/src/mir/helpers.cpp
@@ -213,26 +213,5 @@ const ::HIR::TypeRef& ::MIR::TypeResolve::get_lvalue_type(::HIR::TypeRef& tmp, c
}
const ::HIR::TypeRef* ::MIR::TypeResolve::is_type_owned_box(const ::HIR::TypeRef& ty) const
{
- if( m_lang_Box )
- {
- if( ! ty.m_data.is_Path() ) {
- return nullptr;
- }
- const auto& te = ty.m_data.as_Path();
-
- if( ! te.path.m_data.is_Generic() ) {
- return nullptr;
- }
- const auto& pe = te.path.m_data.as_Generic();
-
- if( pe.m_path != *m_lang_Box ) {
- return nullptr;
- }
- // TODO: Properly assert?
- return &pe.m_params.m_types.at(0);
- }
- else
- {
- return nullptr;
- }
+ return m_resolve.is_type_owned_box(ty);
}
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 889565c4..b780d695 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -757,12 +757,10 @@ namespace {
m_of << " " << inner;
),
(Path,
- //if( m_mir_res ) {
- // if( const auto* ity = m_mir_res->is_type_owned_box(ty) ) {
- // emit_ctype_ptr(*ity, inner);
- // return ;
- // }
- //}
+ if( const auto* ity = m_resolve.is_type_owned_box(ty) ) {
+ emit_ctype_ptr(*ity, inner);
+ return ;
+ }
TU_MATCHA( (te.binding), (tpb),
(Struct,
m_of << "struct s_" << Trans_Mangle(te.path);