Skip to content
Browse files

THRIFT-643. smalltalk: Generated code doesnt load on Squeak3.10.2-717…

…9-basic and PharoCore-1.0-10491rc1 images

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@900660 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent c4ad9be commit b6f4e56bb0c67d6f10391d9a6dff845e72c4100f @toddlipcon toddlipcon committed Jan 19, 2010
Showing with 46 additions and 34 deletions.
  1. +33 −0 compiler/cpp/src/generate/t_generator.h
  2. +13 −33 compiler/cpp/src/generate/t_st_generator.cc
  3. +0 −1 lib/st/thrift.st
View
33 compiler/cpp/src/generate/t_generator.h
@@ -178,6 +178,14 @@ class t_generator {
}
return in;
}
+ /**
+ * Transforms a camel case string to an equivalent one separated by underscores
+ * e.g. aMultiWord -> a_multi_word
+ * someName -> some_name
+ * CamelCase -> camel_case
+ * name -> name
+ * Name -> name
+ */
std::string underscore(std::string in) {
in[0] = tolower(in[0]);
for (size_t i = 1; i < in.size(); ++i) {
@@ -188,6 +196,31 @@ class t_generator {
}
return in;
}
+ /**
+ * Transforms a string with words separated by underscores to a camel case equivalent
+ * e.g. a_multi_word -> aMultiWord
+ * some_name -> someName
+ * name -> name
+ */
+ std::string camelcase(std::string in) {
+ std::ostringstream out;
+ bool underscore = false;
+
+ for (size_t i = 0; i < in.size(); i++) {
+ if (in[i] == '_') {
+ underscore = true;
+ continue;
+ }
+ if (underscore) {
+ out << (char) toupper(in[i]);
+ underscore = false;
+ continue;
+ }
+ out << in[i];
+ }
+
+ return out.str();
+ }
/**
* Get the true type behind a series of typedefs.
View
46 compiler/cpp/src/generate/t_st_generator.cc
@@ -124,7 +124,6 @@ class t_st_generator : public t_oop_generator {
std::string client_class_name();
std::string prefix(std::string name);
std::string declare_field(t_field* tfield);
- std::string sanitize(std::string s);
std::string type_name(t_type* ttype);
std::string function_signature(t_function* tfunction);
@@ -495,7 +494,7 @@ void t_st_generator::generate_st_struct(std::ofstream& out, t_struct* tstruct, b
if (members.size() > 0) {
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if (m_iter != members.begin()) out << " ";
- out << sanitize((*m_iter)->get_name());
+ out << camelcase((*m_iter)->get_name());
}
}
@@ -536,7 +535,7 @@ void t_st_generator::generate_accessors(std::ofstream& out, t_struct* tstruct) {
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
st_accessors(out,
capitalize(type_name(tstruct)),
- sanitize((*m_iter)->get_name()),
+ camelcase((*m_iter)->get_name()),
a_type((*m_iter)->get_type()));
}
out << endl;
@@ -706,8 +705,8 @@ string t_st_generator::struct_writer(t_struct *tstruct, string sname) {
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
bool optional = (*fld_iter)->get_req() == t_field::T_OPTIONAL;
- string fname = (*fld_iter)->get_name();
- string accessor = sname + " " + sanitize(fname);
+ string fname = camelcase((*fld_iter)->get_name());
+ string accessor = sname + " " + camelcase(fname);
if (optional) {
out << indent() << accessor << " ifNotNil: [" << endl;
@@ -765,7 +764,7 @@ string t_st_generator::struct_reader(t_struct *tstruct, string clsName = "") {
indent_up();
out << indent() << found << " := true." << endl <<
- indent() << val << " " << sanitize((*fld_iter)->get_name()) << ": " <<
+ indent() << val << " " << camelcase((*fld_iter)->get_name()) << ": " <<
read_val((*fld_iter)->get_type());
indent_down();
@@ -854,10 +853,10 @@ void t_st_generator::generate_send_method(t_function* function) {
indent_down();
f_ << indent() << "oprot writeStructBegin: " <<
- "(TStruct new name: '" + capitalize(function->get_name()) + "_args')." << endl;
+ "(TStruct new name: '" + capitalize(camelcase(funname)) + "_args')." << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- string fname = (*fld_iter)->get_name();
+ string fname = camelcase((*fld_iter)->get_name());
f_ << indent() << "oprot writeFieldBegin: (TField new name: '" << fname <<
"'; type: " << type_to_enum((*fld_iter)->get_type()) <<
@@ -875,7 +874,7 @@ void t_st_generator::generate_send_method(t_function* function) {
// We only support receiving TResult structures (so this won't work on the server side)
void t_st_generator::generate_recv_method(t_function* function) {
- string funname = function->get_name();
+ string funname = camelcase(function->get_name());
string signature = function_signature(function);
t_struct result(program_, "TResult");
@@ -911,7 +910,7 @@ string t_st_generator::function_types_comment(t_function* fn) {
out << "\"";
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- out << (*f_iter)->get_name() << ": " << type_name((*f_iter)->get_type());
+ out << camelcase((*f_iter)->get_name()) << ": " << type_name((*f_iter)->get_type());
if ((f_iter + 1) != fields.end()) {
out << ", ";
}
@@ -945,7 +944,7 @@ void t_st_generator::generate_service_client(t_service* tservice) {
"\tcategory: '" << generated_category() << "'!\n\n";
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- string funname = (*f_iter)->get_name();
+ string funname = camelcase((*f_iter)->get_name());
string signature = function_signature(*f_iter);
st_method(f_, client_class_name(), signature);
@@ -965,34 +964,14 @@ void t_st_generator::generate_service_client(t_service* tservice) {
}
}
-string t_st_generator::sanitize(string s) {
- std::ostringstream out;
- bool underscore = false;
-
- for (unsigned int i = 0; i < s.size(); i++) {
- if (s[i] == '_') {
- underscore = true;
- continue;
- }
- if (underscore) {
- out << (char) toupper(s[i]);
- underscore = false;
- continue;
- }
- out << s[i];
- }
-
- return out.str();
-}
-
/**
* Renders a function signature of the form 'type name(args)'
*
* @param tfunction Function definition
* @return String of rendered function definition
*/
string t_st_generator::function_signature(t_function* tfunction) {
- return tfunction->get_name() + capitalize(argument_list(tfunction->get_arglist()));
+ return camelcase(tfunction->get_name()) + capitalize(argument_list(tfunction->get_arglist()));
}
/**
@@ -1010,7 +989,8 @@ string t_st_generator::argument_list(t_struct* tstruct) {
} else {
result += " ";
}
- result += (*f_iter)->get_name() + ": " + (*f_iter)->get_name();
+ string name = camelcase((*f_iter)->get_name());
+ result += name + ": " + name;
}
return result;
}
View
1 lib/st/thrift.st
@@ -294,7 +294,6 @@ readSetBegin
!TBinaryProtocol methodsFor: 'reading' stamp: 'pc 02/07/2009 19:00'!
readString
-readString
| sz |
sz := self readI32.
^ sz > 0 ifTrue: [(transport read: sz) asString] ifFalse: ['']! !

0 comments on commit b6f4e56

Please sign in to comment.
Something went wrong with that request. Please try again.