THRIFT-3416 Retire old "xxx_namespace" declarations from the IDL
Client: Compiler (general)
Patch: Jens Geyer
This closes #700
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 0674594..5e218b4 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -657,6 +657,20 @@
}
/**
+ * Prints deprecation notice for old NS declarations that are no longer supported
+ * If new_form is NULL, old_form is assumed to be a language identifier, such as "cpp"
+ * If new_form is not NULL, both arguments are used exactly as given
+ */
+void error_unsupported_namespace_decl(char* old_form, char* new_form) {
+ char* remainder = "";
+ if( new_form == NULL) {
+ new_form = old_form;
+ remainder = "_namespace";
+ }
+ failure("Unsupported declaration '%s%s'. Use 'namespace %s' instead.", old_form, remainder, new_form);
+}
+
+/**
* Prints the version number
*/
void version() {
diff --git a/compiler/cpp/src/main.h b/compiler/cpp/src/main.h
index 8751dd5..98ca754 100644
--- a/compiler/cpp/src/main.h
+++ b/compiler/cpp/src/main.h
@@ -102,6 +102,13 @@
void emit_byte_type_warning();
/**
+ * Prints deprecation notice for old NS declarations that are no longer supported
+ * If new_form is NULL, old_form is assumed to be a language identifier, such as "cpp"
+ * If new_form is not NULL, both arguments are used exactly as given
+ */
+void error_unsupported_namespace_decl(char* old_form, char* new_form = NULL);
+
+/**
* Flex utilities
*/
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 7d96bca..76acda1 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -134,23 +134,23 @@
"true" { yylval.iconst=1; return tok_int_constant; }
"namespace" { return tok_namespace; }
-"cpp_namespace" { return tok_cpp_namespace; }
+"cpp_namespace" { error_unsupported_namespace_decl("cpp"); /* do nothing */ }
"cpp_include" { return tok_cpp_include; }
"cpp_type" { return tok_cpp_type; }
-"java_package" { return tok_java_package; }
-"cocoa_prefix" { return tok_cocoa_prefix; }
-"csharp_namespace" { return tok_csharp_namespace; }
-"delphi_namespace" { return tok_delphi_namespace; }
-"php_namespace" { return tok_php_namespace; }
-"py_module" { return tok_py_module; }
-"perl_package" { return tok_perl_package; }
-"ruby_namespace" { return tok_ruby_namespace; }
-"smalltalk_category" { return tok_smalltalk_category; }
-"smalltalk_prefix" { return tok_smalltalk_prefix; }
+"java_package" { error_unsupported_namespace_decl("java_package", "java"); /* do nothing */ }
+"cocoa_prefix" { error_unsupported_namespace_decl("cocoa_prefix", "cocoa"); /* do nothing */ }
+"csharp_namespace" { error_unsupported_namespace_decl("csharp"); /* do nothing */ }
+"delphi_namespace" { error_unsupported_namespace_decl("delphi"); /* do nothing */ }
+"php_namespace" { error_unsupported_namespace_decl("php"); /* do nothing */ }
+"py_module" { error_unsupported_namespace_decl("py_module", "py"); /* do nothing */ }
+"perl_package" { error_unsupported_namespace_decl("perl_package", "perl"); /* do nothing */ }
+"ruby_namespace" { error_unsupported_namespace_decl("ruby"); /* do nothing */ }
+"smalltalk_category" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ }
+"smalltalk_prefix" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ }
"xsd_all" { return tok_xsd_all; }
"xsd_optional" { return tok_xsd_optional; }
"xsd_nillable" { return tok_xsd_nillable; }
-"xsd_namespace" { return tok_xsd_namespace; }
+"xsd_namespace" { error_unsupported_namespace_decl("xsd"); /* do nothing */ }
"xsd_attrs" { return tok_xsd_attrs; }
"include" { return tok_include; }
"void" { return tok_void; }
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index 59f6b4f..546196a 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -112,24 +112,12 @@
*/
%token tok_include
%token tok_namespace
-%token tok_cpp_namespace
%token tok_cpp_include
%token tok_cpp_type
-%token tok_php_namespace
-%token tok_py_module
-%token tok_perl_package
-%token tok_java_package
%token tok_xsd_all
%token tok_xsd_optional
%token tok_xsd_nillable
-%token tok_xsd_namespace
%token tok_xsd_attrs
-%token tok_ruby_namespace
-%token tok_smalltalk_category
-%token tok_smalltalk_prefix
-%token tok_cocoa_prefix
-%token tok_csharp_namespace
-%token tok_delphi_namespace
/**
* Base datatype keywords
@@ -317,16 +305,6 @@
g_program->set_namespace("*", $3);
}
}
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_cpp_namespace tok_identifier
- {
- pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
- pdebug("Header -> tok_cpp_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("cpp", $2);
- }
- }
| tok_cpp_include tok_literal
{
pdebug("Header -> tok_cpp_include tok_literal");
@@ -335,115 +313,6 @@
g_program->add_cpp_include($2);
}
}
-| tok_php_namespace tok_identifier
- {
- pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
- pdebug("Header -> tok_php_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("php", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_py_module tok_identifier
- {
- pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
- pdebug("Header -> tok_py_module tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("py", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_perl_package tok_identifier
- {
- pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
- pdebug("Header -> tok_perl_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("perl", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_ruby_namespace tok_identifier
- {
- pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
- pdebug("Header -> tok_ruby_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("rb", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_smalltalk_category tok_st_identifier
- {
- pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
- pdebug("Header -> tok_smalltalk_category tok_st_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("smalltalk.category", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_smalltalk_prefix tok_identifier
- {
- pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
- pdebug("Header -> tok_smalltalk_prefix tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("smalltalk.prefix", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_java_package tok_identifier
- {
- pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
- pdebug("Header -> tok_java_package tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("java", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_cocoa_prefix tok_identifier
- {
- pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
- pdebug("Header -> tok_cocoa_prefix tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("cocoa", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_xsd_namespace tok_literal
- {
- pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
- pdebug("Header -> tok_xsd_namespace tok_literal");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("cocoa", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_csharp_namespace tok_identifier
- {
- pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
- pdebug("Header -> tok_csharp_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("csharp", $2);
- }
- }
-/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
-| tok_delphi_namespace tok_identifier
- {
- pwarning(1, "'delphi_namespace' is deprecated. Use 'namespace delphi' instead");
- pdebug("Header -> tok_delphi_namespace tok_identifier");
- declare_valid_program_doctext();
- if (g_parse_mode == PROGRAM) {
- g_program->set_namespace("delphi", $2);
- }
- }
Include:
tok_include tok_literal