From: David Reiss Date: Mon, 6 Aug 2007 20:38:18 +0000 (+0000) Subject: Thrift: More constant enums. X-Git-Tag: 0.2.0~1279 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=202111d2e9cb351ac77929f573569625a3937308;p=common%2Fthrift.git Thrift: More constant enums. Summary: Make enum constants as structure defaults work. Make enum constants as constant map keys work. Un-break the generated skeleton servers. Reviewed By: mcslee Test Plan: cd test ../compiler/cpp/thrift -cpp ConstantsDemo.thrift g++ -I../lib/cpp/src -c gen-cpp/*.cpp Also compared the generated output to the old generated output. Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665193 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 354926d8..fc205945 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -327,7 +327,7 @@ string t_cpp_generator::render_const_value(ofstream& out, string name, t_type* t throw "compiler error: no const of base type " + tbase; } } else if (type->is_enum()) { - render << value->get_integer(); + render << "(" << type->get_name() << ")" << value->get_integer(); } else { string t = tmp("tmp"); indent(out) << type_name(type) << " " << t << ";" << endl; @@ -391,7 +391,7 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, while (t->is_typedef()) { t = ((t_typedef*)t)->get_type(); } - if (t->is_base_type() || t->is_enum()) { + if (t->is_base_type()) { string dval; if (t->is_enum()) { dval += "(" + t->get_name() + ")"; @@ -412,6 +412,8 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, } out << " {" << endl; indent_up(); + // TODO(dreiss): When everything else in Thrift is perfect, + // do more of these in the initializer list. for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { t_type* t = (*m_iter)->get_type(); while (t->is_typedef()) { @@ -1613,6 +1615,8 @@ void t_cpp_generator::generate_service_skeleton(t_service* tservice) { "using namespace facebook::thrift::protocol;" << endl << "using namespace facebook::thrift::transport;" << endl << "using namespace facebook::thrift::server;" << endl << + endl << + "using boost::shared_ptr;" << endl << endl; if (!ns.empty()) { diff --git a/test/ConstantsDemo.thrift b/test/ConstantsDemo.thrift index 3af9f932..8cc6a1f7 100644 --- a/test/ConstantsDemo.thrift +++ b/test/ConstantsDemo.thrift @@ -10,7 +10,11 @@ enum constants { TWO = 2 } -const map GEN_ENUM_NAMES = {ONE : "HOWDY", TWO: PARTNER} +struct thing2 { + 1: constants val = TWO +} + +const map GEN_ENUM_NAMES = {ONE : "HOWDY", TWO: PARTNER} const i32 hex_const = 0x0001F