THRIFT-178. java, csharp, cpp: Final Keyword
authorBryan Duxbury <bryanduxbury@apache.org>
Sun, 1 Feb 2009 16:56:29 +0000 (16:56 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Sun, 1 Feb 2009 16:56:29 +0000 (16:56 +0000)
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
compiler/cpp/src/generate/t_csharp_generator.cc
compiler/cpp/src/generate/t_java_generator.cc
compiler/cpp/src/thriftl.ll

index 4cb3538..318c36b 100644 (file)
@@ -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_) {
index 088a025..ee56f5e 100644 (file)
@@ -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, ";
index 30e7f78..3d24ece 100644 (file)
@@ -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 ";
index 62cdb16..1051e27 100644 (file)
@@ -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); }