Author: dreiss
Date: Thu Sep  2 16:41:45 2010
New Revision: 992012

URL: http://svn.apache.org/viewvc?rev=992012&view=rev
Log:
Allow "*" as a catch-all namespace.

In an IDL file, you can can now declare "namespace * foo",
which will apply to any language not explicitly specified.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h
    incubator/thrift/trunk/compiler/cpp/src/thriftl.ll
    incubator/thrift/trunk/compiler/cpp/src/thrifty.yy
    incubator/thrift/trunk/test/ThriftTest.thrift

Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h?rev=992012&r1=992011&r2=992012&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h Thu Sep  2 
16:41:45 2010
@@ -189,11 +189,12 @@ class t_program : public t_doc {
   }
 
   std::string get_namespace(std::string language) const {
-    std::map<std::string, std::string>::const_iterator iter = 
namespaces_.find(language);
-    if (iter == namespaces_.end()) {
-      return std::string();
+    std::map<std::string, std::string>::const_iterator iter;
+    if ((iter = namespaces_.find(language)) != namespaces_.end() ||
+        (iter = namespaces_.find("*"     )) != namespaces_.end()) {
+      return iter->second;
     }
-    return iter->second;
+    return std::string();
   }
 
   // Language specific namespace / packaging

Modified: incubator/thrift/trunk/compiler/cpp/src/thriftl.ll
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/thriftl.ll?rev=992012&r1=992011&r2=992012&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/thriftl.ll (original)
+++ incubator/thrift/trunk/compiler/cpp/src/thriftl.ll Thu Sep  2 16:41:45 2010
@@ -342,6 +342,11 @@ literal_begin (['\"])
 }
 
 
+. {
+  /* Catch-all to let us catch "*" in the parser. */
+  return (int) yytext[0];
+}
+
 %%
 
 /* vim: filetype=lex

Modified: incubator/thrift/trunk/compiler/cpp/src/thrifty.yy
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/thrifty.yy?rev=992012&r1=992011&r2=992012&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/thrifty.yy (original)
+++ incubator/thrift/trunk/compiler/cpp/src/thrifty.yy Thu Sep  2 16:41:45 2010
@@ -280,6 +280,13 @@ Header:
         g_program->set_namespace($2, $3);
       }
     }
+| tok_namespace '*' tok_identifier
+    {
+      pdebug("Header -> tok_namespace * tok_identifier");
+      if (g_parse_mode == PROGRAM) {
+        g_program->set_namespace("*", $3);
+      }
+    }
 /* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
 | tok_cpp_namespace tok_identifier
     {

Modified: incubator/thrift/trunk/test/ThriftTest.thrift
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/test/ThriftTest.thrift?rev=992012&r1=992011&r2=992012&view=diff
==============================================================================
--- incubator/thrift/trunk/test/ThriftTest.thrift (original)
+++ incubator/thrift/trunk/test/ThriftTest.thrift Thu Sep  2 16:41:45 2010
@@ -28,6 +28,7 @@ namespace perl ThriftTest
 namespace csharp Thrift.Test
 namespace js ThriftTest
 namespace st ThriftTest
+namespace * thrift.test
 
 /**
  * Docstring!


Reply via email to