Allow the specification of custom container types in Thrift IDL files

Summary: If you want your map to be a hash_map instead of an stl::map, we now have a directive in Thrift to let you do that.

Instead of:
map<i32,i32>

You can do:
map[cpp:hash_map<int32_t,int32_t>]<i32,i32>

This tells the Thrift compiler to explicitly use whatever type was specified in the brackets when generating C++ code, instead of the implied Thrift type.

Reviewed By: aditya


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664828 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrift.y b/compiler/cpp/src/thrift.y
index 404c80b..3bf8b53 100644
--- a/compiler/cpp/src/thrift.y
+++ b/compiler/cpp/src/thrift.y
@@ -44,6 +44,7 @@
  * Strings identifier
  */
 %token<id>     tok_identifier
+%token<id>     tok_cpptype
 
 /**
  * Integer constant value
@@ -122,6 +123,7 @@
 
 %type<tstruct>   ThrowsOptional
 %type<tbool>     AsyncOptional
+%type<id>        CppTypeOptional
 
 %%
 
@@ -449,24 +451,43 @@
     }
 
 MapType:
-  tok_map '<' FieldType ',' FieldType '>'
+  tok_map CppTypeOptional '<' FieldType ',' FieldType '>'
     {
       pdebug("MapType -> tok_map <FieldType, FieldType>");
-      $$ = new t_map($3, $5);
+      $$ = new t_map($4, $6);
+      if ($2 != NULL) {
+        ((t_container*)$$)->set_cpp_name(std::string($2));
+      }
     }
 
 SetType:
-  tok_set '<' FieldType '>'
+  tok_set CppTypeOptional '<' FieldType '>'
     {
       pdebug("SetType -> tok_set<FieldType>");
-      $$ = new t_set($3);
+      $$ = new t_set($4);
+      if ($2 != NULL) {
+        ((t_container*)$$)->set_cpp_name(std::string($2));
+      }
     }
 
 ListType:
-  tok_list '<' FieldType '>'
+  tok_list CppTypeOptional '<' FieldType '>'
     {
       pdebug("ListType -> tok_list<FieldType>");
-      $$ = new t_list($3);
+      $$ = new t_list($4);
+      if ($2 != NULL) {
+        ((t_container*)$$)->set_cpp_name(std::string($2));
+      }
+    }
+
+CppTypeOptional:
+  tok_cpptype
+    {
+      $$ = $1;
+    }
+|
+    {
+      $$ = NULL;
     }
 
 %%