From: Kevin Clark Date: Tue, 24 Mar 2009 15:56:19 +0000 (+0000) Subject: THRIFT-399. hs: Fix set and number issues in generated constant code X-Git-Tag: 0.2.0~231 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=4798a7ad12f3c1a0cea7495bbbbc7d3e253601d8;p=common%2Fthrift.git THRIFT-399. hs: Fix set and number issues in generated constant code Author: Spiridon Eliopoulos git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@757864 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_hs_generator.cc b/compiler/cpp/src/generate/t_hs_generator.cc index 91a72044..95f04ffe 100644 --- a/compiler/cpp/src/generate/t_hs_generator.cc +++ b/compiler/cpp/src/generate/t_hs_generator.cc @@ -287,6 +287,7 @@ void t_hs_generator::generate_const(t_const* tconst) { string name = decapitalize(tconst->get_name()); t_const_value* value = tconst->get_value(); + indent(f_consts_) << name << " :: " << render_hs_type(type, false) << endl; indent(f_consts_) << name << " = " << render_const_value(type, value) << endl << endl; } @@ -383,13 +384,24 @@ string t_hs_generator::render_const_value(t_type* type, t_const_value* value) { out << "(" << key << ","<< val << ")"; } out << "])"; - } else if (type->is_list()) { + } else if (type->is_list() || type->is_set()) { t_type* etype; - etype = ((t_list*)type)->get_elem_type(); - out << "["; + + if (type->is_list()) { + etype = ((t_list*) type)->get_elem_type(); + } else { + etype = ((t_set*) type)->get_elem_type(); + } + const vector& val = value->get_list(); vector::const_iterator v_iter; - bool first=true; + bool first = true; + + if (type->is_set()) + out << "(Set.fromList "; + + out << "["; + for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { if(first) first=false; @@ -397,17 +409,10 @@ string t_hs_generator::render_const_value(t_type* type, t_const_value* value) { out << ","; out << render_const_value(etype, *v_iter); } + out << "]"; - } else if (type->is_set()) { - t_type* etype = ((t_set*)type)->get_elem_type(); - const vector& val = value->get_list(); - vector::const_iterator v_iter; - out << "(mkSet ["; - for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { - string val = render_const_value(etype, *v_iter); - out << val; - } - out << "])"; + if (type->is_set()) + out << ")"; } else { throw "CANNOT GENERATE CONSTANT FOR TYPE: " + type->get_name(); }