diff options
author | John Hodge <tpg@mutabah.net> | 2018-02-25 20:56:24 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-02-25 20:56:24 +0800 |
commit | 11081bf939c598a4f21018b5562f53caa57467b8 (patch) | |
tree | 6ea76fce95c14e2bc7b0511e5d5322d8efe2f6cd | |
parent | f53157332c997212f78836343a8f543b5b45b334 (diff) | |
download | mrust-11081bf939c598a4f21018b5562f53caa57467b8.tar.gz |
Codegen C - Literals and omitted ZSTs
-rw-r--r-- | src/trans/codegen_c.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 3dddb0c2..b00e95c6 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1456,12 +1456,18 @@ namespace { if( ty.m_data.is_Array() ) m_of << "{"; m_of << "{"; + bool emitted_field = false; for(unsigned int i = 0; i < e.size(); i ++) { - if(i != 0) m_of << ","; + const auto& ity = get_inner_type(0, i); + // Don't emit ZSTs if they're being omitted + if( this->type_is_bad_zst(ity) ) + continue ; + if(emitted_field) m_of << ","; + emitted_field = true; m_of << " "; - emit_literal(get_inner_type(0, i), e[i], params); + emit_literal(ity, e[i], params); } - if( (ty.m_data.is_Path() || ty.m_data.is_Tuple()) && e.size() == 0 && m_options.disallow_empty_structs ) + if( (ty.m_data.is_Path() || ty.m_data.is_Tuple()) && !emitted_field && m_options.disallow_empty_structs ) m_of << "0"; m_of << " }"; if( ty.m_data.is_Array() ) @@ -4578,10 +4584,19 @@ namespace { } else { + bool emitted_field = false; for(unsigned int i = 0; i < e.size(); i ++) { - if(i != 0) m_of << ";\n\t"; + const auto& ity = get_inner_type(0, i); + // Don't emit ZSTs if they're being omitted + if( this->type_is_bad_zst(ity) ) + continue ; + if(emitted_field) m_of << ";\n\t"; + emitted_field = true; assign_from_literal([&](){ emit_dst(); m_of << "._" << i; }, get_inner_type(0, i), e[i]); } + //if( !emitted_field ) + //{ + //} } ), (Variant, |