Modify Thrift parser to disallow optional/required keywords in argument lists

Reviewed By: dreiss

Test Plan: Toss an optional/required in an arg list, check that it's ignored and compiler spits a warning


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index a96bfc4..cd727c1 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -25,6 +25,7 @@
  * assigned starting from -1 and working their way down.
  */
 int y_field_val = -1;
+int g_arglist = 0;
 
 %}
 
@@ -665,14 +666,24 @@
     }
 
 Service:
-  tok_service tok_identifier Extends '{' FunctionList '}'
+  tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
     {
       pdebug("Service -> tok_service tok_identifier { FunctionList }");
-      $$ = $5;
+      $$ = $6;
       $$->set_name($2);
       $$->set_extends($3);
     }
 
+FlagArgs:
+    {
+       g_arglist = 1;
+    }
+
+UnflagArgs:
+    {
+       g_arglist = 0;
+    }
+
 Extends:
   tok_extends tok_identifier
     {
@@ -789,11 +800,25 @@
 FieldRequiredness:
   tok_required
     {
-      $$ = t_field::REQUIRED;
+      if (g_arglist) {
+        if (g_parse_mode == PROGRAM) {
+          pwarning(1, "required keyword is ignored in argument lists.\n");
+        }
+        $$ = t_field::OPT_IN_REQ_OUT;
+      } else {
+        $$ = t_field::REQUIRED;
+      }
     }
 | tok_optional
     {
-      $$ = t_field::OPTIONAL;
+      if (g_arglist) {
+        if (g_parse_mode == PROGRAM) {
+          pwarning(1, "optional keyword is ignored in argument lists.\n");
+        }
+        $$ = t_field::OPT_IN_REQ_OUT;
+      } else {
+        $$ = t_field::OPTIONAL;
+      }
     }
 |
     {