Committing code gen changes for const ref args to functions in Thrift
Reviewed By: aditya
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664909 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 953bb55..68a491b 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -102,7 +102,7 @@
*/
void t_cpp_generator::generate_typedef(t_typedef* ttypedef) {
f_types_ <<
- indent() << "typedef " << type_name(ttypedef->get_type(), false, true) << " " << ttypedef->get_symbolic() << ";" << endl <<
+ indent() << "typedef " << type_name(ttypedef->get_type(), true) << " " << ttypedef->get_symbolic() << ";" << endl <<
endl;
}
@@ -1947,9 +1947,18 @@
* @param ttype The type
* @return String of the type name, i.e. std::set<type>
*/
-string t_cpp_generator::type_name(t_type* ttype, bool arg, bool in_typedef) {
+string t_cpp_generator::type_name(t_type* ttype, bool in_typedef, bool arg) {
if (ttype->is_base_type()) {
- return base_type_name(((t_base_type*)ttype)->get_base());
+ string bname = base_type_name(((t_base_type*)ttype)->get_base());
+ if (!arg) {
+ return bname;
+ }
+
+ if (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING) {
+ return "const " + bname + "&";
+ } else {
+ return "const " + bname;
+ }
}
// Check for a custom overloaded C++ name
@@ -2109,7 +2118,7 @@
} else {
result += ", ";
}
- result += type_name((*f_iter)->get_type()) + " " + (*f_iter)->get_name();
+ result += type_name((*f_iter)->get_type(), false, true) + " " + (*f_iter)->get_name();
}
return result;
}
diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h
index 83780ed..aae6f4f 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.h
+++ b/compiler/cpp/src/generate/t_cpp_generator.h
@@ -127,7 +127,7 @@
std::string namespace_prefix(std::string ns);
std::string namespace_open(std::string ns);
std::string namespace_close(std::string ns);
- std::string type_name(t_type* ttype, bool arg=false, bool in_typedef=false);
+ std::string type_name(t_type* ttype, bool in_typedef=false, bool arg=false);
std::string base_type_name(t_base_type::t_base tbase);
std::string declare_field(t_field* tfield, bool init=false);
std::string function_signature(t_function* tfunction, std::string prefix="");