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.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@992012 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 4f8f151..daad6b9 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -189,11 +189,12 @@
}
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
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 84e02bb..b8c36c3 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -342,6 +342,11 @@
}
+. {
+ /* Catch-all to let us catch "*" in the parser. */
+ return (int) yytext[0];
+}
+
%%
/* vim: filetype=lex
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index d12cca3..cdedee0 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -280,6 +280,13 @@
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
{