From: Mark Slee Date: Mon, 10 Sep 2007 22:08:49 +0000 (+0000) Subject: Modify Thrift parser to disallow optional/required keywords in argument lists X-Git-Tag: 0.2.0~1217 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=7816572784c7ddafc2c4350b221469af12d198fc;p=common%2Fthrift.git 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 a96bfc40..cd727c10 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 @@ Xception: } 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 @@ FieldIdentifier: 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; + } } | {