You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2010/12/13 20:17:22 UTC
svn commit: r1045320 -
/thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc
Author: bryanduxbury
Date: Mon Dec 13 19:17:22 2010
New Revision: 1045320
URL: http://svn.apache.org/viewvc?rev=1045320&view=rev
Log:
THRIFT-1020. ocaml: OCaml compiler generates invalid OCaml
This patch resolves problems with double constants and adds a copy method to generated structs.
Patch: Richard Low
Modified:
thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc
Modified: thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc?rev=1045320&r1=1045319&r2=1045320&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_ocaml_generator.cc Mon Dec 13 19:17:22 2010
@@ -366,6 +366,8 @@ void t_ocaml_generator::generate_const(t
string t_ocaml_generator::render_const_value(t_type* type, t_const_value* value) {
type = get_true_type(type);
std::ostringstream out;
+ // OCaml requires all floating point numbers contain a decimal point
+ out.setf(ios::showpoint);
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
@@ -385,9 +387,7 @@ string t_ocaml_generator::render_const_v
break;
case t_base_type::TYPE_DOUBLE:
if (value->get_type() == t_const_value::CV_INTEGER) {
- out << value->get_integer();
- } else if(value->get_double() == 0.0) {
- out << "0.0"; // OCaml can't bear '0' in place of double.
+ out << value->get_integer() << ".0";
} else {
out << value->get_double();
}
@@ -733,7 +733,7 @@ void t_ocaml_generator::generate_ocaml_s
vector<t_field*>::const_iterator m_iter;
string tname = type_name(tstruct);
indent(out) << "class " << tname << " :" << endl;
- indent(out) << "object" << endl;
+ indent(out) << "object ('a)" << endl;
indent_up();
@@ -750,7 +750,7 @@ void t_ocaml_generator::generate_ocaml_s
indent(out) << "method reset_" << mname << " : unit" << endl;
}
}
- indent(out) << "method copy : " << tname << endl;
+ indent(out) << "method copy : 'a" << endl;
indent(out) << "method write : Protocol.t -> unit" << endl;
indent_down();
indent(out) << "end" << endl;