[thrift] service functions that begin with a Capital now work for Erlang ...
Summary: ... The main interface function has the same name, but as an escaped atom
(ie 'CapitalizedFun'(Arg1, Arg2) -> is the function sig)
Reviewed by: dweatherford
Test Plan: tested with the following thrift
service foo {
Struct1 CapitalizedFun(1: list<Struct2> param);
}
Generated erlang code now compiles
Revert Plan: sure
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665408 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc
index de807a7..44683cd 100644
--- a/compiler/cpp/src/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/generate/t_erl_generator.cc
@@ -417,7 +417,7 @@
// Generate deserialization code for known cases
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- out << indent() << "(Fid == " << (*f_iter)->get_key() << ") and (Ftype == "
+ out << indent() << "(Fid == " << (*f_iter)->get_key() << "), (Ftype == "
<< type_to_enum((*f_iter)->get_type()) << ") ->" << endl;
indent_up();
@@ -698,7 +698,7 @@
export_function(*f_iter, "send_");
indent(f_service_) <<
- "send_" << function_signature(*f_iter) << " ->" << endl;
+ function_signature(*f_iter, "send_") << " ->" << endl;
indent_up();
std::string argsname = capitalize((*f_iter)->get_name() + "_args");
@@ -708,7 +708,7 @@
indent() << "Oprot = This#" << service_name_ << ".oprot," << endl <<
indent() << "Seqid = This#" << service_name_ << ".seqid," << endl <<
indent() << "?R3(Oprot, writeMessageBegin, \"" << (*f_iter)->get_name() << "\", ?tMessageType_CALL, Seqid)," << endl <<
- indent() << "Args = #" << (*f_iter)->get_name() << "_args{";
+ indent() << "Args = #" << uncapitalize(funname) << "_args{";
bool first = true;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
@@ -717,7 +717,7 @@
<< "=" << capitalize((*fld_iter)->get_name());
}
f_service_ << "}," << endl;
- indent(f_service_) << (*f_iter)->get_name() << "_args_write(Args, Oprot)," << endl;
+ indent(f_service_) << uncapitalize(funname) << "_args_write(Args, Oprot)," << endl;
// Write to the stream
f_service_ <<
@@ -932,8 +932,9 @@
f_service_ <<
indent() << "Seqid, Oprot, % suppress unused warnings" << endl;
- string argsname = tfunction->get_name() + "_args";
- string resultname = tfunction->get_name() + "_result";
+ string ucfunname = uncapitalize(tfunction->get_name());
+ string argsname = ucfunname + "_args";
+ string resultname = ucfunname + "_result";
f_service_ <<
indent() << "_Args = " << argsname << "_read(Iprot)," << endl <<
@@ -969,7 +970,7 @@
if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) {
f_service_<< "Res = ";
}
- f_service_ << "HandlerModule:" << tfunction->get_name() << "(";
+ f_service_ << "HandlerModule:" << atomize(tfunction->get_name()) << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
@@ -978,7 +979,7 @@
} else {
f_service_ << ", ";
}
- f_service_ << "_Args#" << tfunction->get_name() << "_args." << (*f_iter)->get_name();
+ f_service_ << "_Args#" << argsname << "." << (*f_iter)->get_name();
}
f_service_ << ")," << endl;
if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) {
@@ -1004,7 +1005,7 @@
if (!tfunction->is_async()) {
f_service_ <<
indent() << "?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_REPLY, Seqid)," << endl <<
- indent() << tfunction->get_name() << "_result_write(Result, Oprot)," << endl;
+ indent() << ucfunname << "_result_write(Result, Oprot)," << endl;
}
indent(f_service_) << "Result" << endl;
indent_down();
@@ -1459,7 +1460,7 @@
string t_erl_generator::function_signature(t_function* tfunction,
string prefix) {
return
- prefix + tfunction->get_name() +
+ atomize(prefix + tfunction->get_name()) +
"(This" + capitalize(argument_list(tfunction->get_arglist())) + ")";
}
@@ -1472,7 +1473,8 @@
} else {
export_lines_ << ", ";
}
- export_lines_ << name << "/" << num;
+
+ export_lines_ << atomize(name) << "/" << num;
}
void t_erl_generator::export_types_function(t_function* tfunction,
diff --git a/compiler/cpp/src/generate/t_erl_generator.h b/compiler/cpp/src/generate/t_erl_generator.h
index 831bb21..a556e9a 100644
--- a/compiler/cpp/src/generate/t_erl_generator.h
+++ b/compiler/cpp/src/generate/t_erl_generator.h
@@ -16,7 +16,7 @@
class t_erl_generator : public t_oop_generator {
public:
t_erl_generator(t_program* program) :
- t_oop_generator(program)
+ t_oop_generator(program)
{
program_name_[0] = tolower(program_name_[0]);
service_name_[0] = tolower(service_name_[0]);
@@ -68,18 +68,18 @@
*/
void generate_deserialize_field (std::ostream &out,
- t_field* tfield,
+ t_field* tfield,
std::string prefix="",
bool inclass=false);
-
+
void generate_deserialize_struct (std::ostream &out,
t_struct* tstruct,
std::string prefix="");
-
+
void generate_deserialize_container (std::ostream &out,
t_type* ttype,
std::string prefix="");
-
+
void generate_deserialize_set_element (std::ostream &out,
t_set* tset,
std::string prefix="");
@@ -141,6 +141,14 @@
return in;
}
+ std::string atomize(std::string in) {
+ if (isupper(in[0])) {
+ return "'" + in + "'";
+ } else {
+ return in;
+ }
+ }
+
private:
/**
@@ -156,9 +164,9 @@
/**
* write out headers and footers for hrl files
*/
-
+
void hrl_header(std::ostream& out, std::string name);
- void hrl_footer(std::ostream& out, std::string name);
+ void hrl_footer(std::ostream& out, std::string name);
/**
* stuff to spit out at the top of generated files
@@ -178,7 +186,7 @@
std::ofstream f_types_file_;
std::ofstream f_types_hrl_file_;
- std::ofstream f_consts_;
+ std::ofstream f_consts_;
std::ostringstream f_service_;
std::ofstream f_service_file_;
std::ofstream f_service_hrl_;