You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2009/03/24 16:56:21 UTC
svn commit: r757864 -
/incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc
Author: kclark
Date: Tue Mar 24 15:56:19 2009
New Revision: 757864
URL: http://svn.apache.org/viewvc?rev=757864&view=rev
Log:
THRIFT-399. hs: Fix set and number issues in generated constant code
Author: Spiridon Eliopoulos
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc?rev=757864&r1=757863&r2=757864&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc Tue Mar 24 15:56:19 2009
@@ -287,6 +287,7 @@
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 @@
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<t_const_value*>& val = value->get_list();
vector<t_const_value*>::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 @@
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<t_const_value*>& val = value->get_list();
- vector<t_const_value*>::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();
}