From 0b94a427d2c4ad46cfbf20529067240b8a8b92e0 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 22 Feb 2017 22:17:07 +0800 Subject: MIR - Restrict Constant::Bytes to returning &[u8; N] --- src/trans/codegen_c.cpp | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index b02769a0..b74589c2 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -2838,35 +2838,16 @@ namespace { m_of << (c.v ? "true" : "false"); ), (Bytes, - // TODO: Need to know the desired value for this - // - Ideally, Bytes would always return a thin pointer (and - // be combined with a MakeDST to make a fat pointer) - ::HIR::TypeRef tmp; - const auto& ty = dst_ptr ? m_mir_res->get_lvalue_type(tmp, *dst_ptr) : tmp = ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, ::HIR::CoreType::U8); - MIR_ASSERT(*m_mir_res, ty.m_data.is_Borrow(), "Const::Bytes returning non-borrow - " << ty); - if( !dst_ptr || ty.m_data.as_Borrow().inner->m_data.is_Array() ) { - // Array borrow : Cast the C string to the array - // - Laziness - m_of << "(void*)\"" << ::std::oct; - for(const auto& v : c) { - if( ' ' <= v && v < 0x7F && v != '"' && v != '\\' ) - m_of << v; - else - m_of << "\\" << (unsigned int)v; - } - m_of << "\"" << ::std::dec; - } - else { - // Slice borrow (asumed), pointer and metadata - m_of << "make_sliceptr(\"" << ::std::oct; - for(const auto& v : c) { - if( ' ' <= v && v < 0x7F && v != '"' && v != '\\' ) - m_of << v; - else - m_of << "\\" << (unsigned int)v; - } - m_of << "\", " << ::std::dec << c.size() << ")"; + // Array borrow : Cast the C string to the array + // - Laziness + m_of << "(void*)\"" << ::std::oct; + for(const auto& v : c) { + if( ' ' <= v && v < 0x7F && v != '"' && v != '\\' ) + m_of << v; + else + m_of << "\\" << (unsigned int)v; } + m_of << "\"" << ::std::dec; ), (StaticString, m_of << "make_sliceptr(\"" << ::std::oct; -- cgit v1.2.3