From 056bcb69477a12381bdb007debf55e654c1be257 Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Sun, 1 Feb 2009 16:56:29 +0000 Subject: [PATCH] THRIFT-178. java, csharp, cpp: Final Keyword The lexer has been changed to make "final" a non-reserved word, and the java, csharp, and cpp compilers now look for the final annotation and amend their class declarations appropriately. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@739788 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_cpp_generator.cc | 8 +++++--- compiler/cpp/src/generate/t_csharp_generator.cc | 4 +++- compiler/cpp/src/generate/t_java_generator.cc | 5 ++++- compiler/cpp/src/thriftl.ll | 1 - 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 4cb35384..318c36be 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -680,9 +680,11 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, scope_down(out); } - out << - endl << - indent() << "virtual ~" << tstruct->get_name() << "() throw() {}" << endl << endl; + if (tstruct->annotations_.find("final") == tstruct->annotations_.end()) { + out << + endl << + indent() << "virtual ~" << tstruct->get_name() << "() throw() {}" << endl << endl; + } // Pointer to this structure's reflection local typespec. if (gen_dense_) { diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc index 088a025b..ee56f5e3 100644 --- a/compiler/cpp/src/generate/t_csharp_generator.cc +++ b/compiler/cpp/src/generate/t_csharp_generator.cc @@ -393,7 +393,9 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream &out, t_stru out << endl; indent(out) << "[Serializable]" << endl; - indent(out) << "public class " << tstruct->get_name() << " : "; + bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end()); + + indent(out) << "public " << (is_final ? "sealed " : "") << "class " << tstruct->get_name() << " : "; if (is_exception) { out << "Exception, "; diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index 30e7f78b..3d24ece4 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -596,8 +596,11 @@ void t_java_generator::generate_java_struct_definition(ofstream &out, bool is_result) { generate_java_doc(out, tstruct); + bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end()); + indent(out) << - "public " << (in_class ? "static " : "") << "class " << tstruct->get_name() << " "; + "public " << (is_final ? "final " : "") << + (in_class ? "static " : "") << "class " << tstruct->get_name() << " "; if (is_exception) { out << "extends Exception "; diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll index 62cdb16c..1051e27f 100644 --- a/compiler/cpp/src/thriftl.ll +++ b/compiler/cpp/src/thriftl.ll @@ -141,7 +141,6 @@ st_identifier ([a-zA-Z-][\.a-zA-Z_0-9-]*) "except" { thrift_reserved_keyword(yytext); } "exec" { thrift_reserved_keyword(yytext); } "false" { thrift_reserved_keyword(yytext); } -"final" { thrift_reserved_keyword(yytext); } "finally" { thrift_reserved_keyword(yytext); } "float" { thrift_reserved_keyword(yytext); } "for" { thrift_reserved_keyword(yytext); } -- 2.17.1