THRIFT-2558: CSharp gen tries to add str + int
authorra <ra@apache.org>
Fri, 30 May 2014 13:31:00 +0000 (06:31 -0700)
committerra <ra@apache.org>
Fri, 30 May 2014 13:31:00 +0000 (06:31 -0700)
Client: C# Compiler
Patch: Randy Abernethy

The C# generator attempts to throw a str + int string in
several places producing undesirable results. This patch
uses stringstream to concatenate the string representations.

compiler/cpp/src/generate/t_csharp_generator.cc

index 5d6fb16..617cbf0 100644 (file)
@@ -464,7 +464,11 @@ std::string t_csharp_generator::render_const_value(ofstream& out, string name, t
         }
         break;
       default:
-        throw "compiler error: no const of base type " + tbase;
+      {
+        std::stringstream ss;
+        ss << "compiler error: no const of base type " << tbase;
+        throw ss.str();
+      }
     }
   } else if (type->is_enum()) {
     render << type->get_name() << "." << value->get_identifier_name();
@@ -2034,7 +2038,11 @@ void t_csharp_generator::generate_deserialize_field(ofstream& out, t_field* tfie
           out << "ReadDouble();";
           break;
         default:
-          throw "compiler error: no C# name for base type " + tbase;
+        {
+          std::stringstream ss;
+          ss << "compiler error: no C# name for base type " << tbase;
+          throw ss.str();
+        }
       }
     } else if (type->is_enum()) {
       out << "ReadI32();";
@@ -2209,7 +2217,11 @@ void t_csharp_generator::generate_deserialize_list_element(ofstream& out, t_list
           out << "WriteDouble(" << nullable_name << ");";
           break;
         default:
-          throw "compiler error: no C# name for base type " + tbase;
+        {
+          std::stringstream ss;
+          ss << "compiler error: no C# name for base type " << tbase;
+          throw ss.str();
+        }
       }
     } else if (type->is_enum()) {
       out << "WriteI32((int)" << nullable_name << ");";
@@ -2453,7 +2465,11 @@ string t_csharp_generator::base_type_name(t_base_type* tbase, bool in_container,
     case t_base_type::TYPE_DOUBLE:
       return "double" + postfix;
     default:
-      throw "compiler error: no C# name for base type " + tbase->get_base();
+    {
+      std::stringstream ss;
+      ss << "compiler error: no C# name for base type " << tbase->get_base();
+      throw ss.str();
+    }
   }
 }