From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 684F221A04820 for ; Fri, 31 Mar 2017 19:25:00 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 31 Mar 2017 19:25:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,255,1486454400"; d="scan'208";a="840628413" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by FMSMGA003.fm.intel.com with ESMTP; 31 Mar 2017 19:24:59 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 31 Mar 2017 19:24:59 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 31 Mar 2017 19:24:59 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.212]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.253]) with mapi id 14.03.0248.002; Sat, 1 Apr 2017 10:24:57 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] BaseTools: Enhance expression to support some more operation Thread-Index: AQHSqiomtCtD7mgobE+wOSGdEhtPi6Gvyflw Date: Sat, 1 Apr 2017 02:24:56 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D707944@shsmsx102.ccr.corp.intel.com> References: <1490970098-52308-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1490970098-52308-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: Enhance expression to support some more operation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Apr 2017 02:25:00 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: Zhu, Yonghong >Sent: Friday, March 31, 2017 10:22 PM >To: edk2-devel@lists.01.org >Cc: Gao, Liming >Subject: [Patch] BaseTools: Enhance expression to support some more >operation > >Enhance expression to support some more operation that allowed in the >spec, eg: *, /, %, <<, >>, ~. > >Cc: Liming Gao >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Yonghong Zhu >--- > BaseTools/Source/Python/Common/Expression.py | 28 >+++++++++++++++++++++++----- > 1 file changed, 23 insertions(+), 5 deletions(-) > >diff --git a/BaseTools/Source/Python/Common/Expression.py >b/BaseTools/Source/Python/Common/Expression.py >index 7b3030c..6d002f5 100644 >--- a/BaseTools/Source/Python/Common/Expression.py >+++ b/BaseTools/Source/Python/Common/Expression.py >@@ -1,9 +1,9 @@ > ## @file > # This file is used to parse and evaluate expression in directive or PCD = value. > # >-# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
>+# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
> # This program and the accompanying materials > # are licensed and made available under the terms and conditions of the B= SD >License > # which accompanies this distribution. The full text of the license ma= y be >found at > # http://opensource.org/licenses/bsd-license.php > # >@@ -127,11 +127,11 @@ class ValueExpression(object): > 'GT' : '>' , 'LT' : '<', > 'GE' : '>=3D' , 'LE' : '<=3D', > 'IN' : 'in' > } > >- NonLetterOpLst =3D ['+', '-', '&', '|', '^', '!', '=3D', '>', '<'] >+ NonLetterOpLst =3D ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<'= , '>>', '!', '=3D', '>', '<'] > > PcdPattern =3D re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za= - >z_]*$') > HexPattern =3D re.compile(r'0[xX][0-9a-fA-F]+$') > RegGuidPattern =3D re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-f= A-F]{4}- >[0-9a-fA-F]{4}-[0-9a-fA-F]{12}') > >@@ -160,10 +160,14 @@ class ValueExpression(object): > EvalStr =3D '' > if Operator in ["!", "NOT", "not"]: > if type(Oprand1) =3D=3D type(''): > raise BadExpression(ERR_STRING_EXPR % Operator) > EvalStr =3D 'not Oprand1' >+ elif Operator in ["~"]: >+ if type(Oprand1) =3D=3D type(''): >+ raise BadExpression(ERR_STRING_EXPR % Operator) >+ EvalStr =3D '~ Oprand1' > else: > if Operator in ["+", "-"] and (type(True) in [type(Oprand1), >type(Oprand2)]): > # Boolean in '+'/'-' will be evaluated but raise warning > WrnExp =3D WrnExpression(WRN_BOOL_EXPR) > elif type('') in [type(Oprand1), type(Oprand2)] and type(Opra= nd1)!=3D >type(Oprand2): >@@ -351,25 +355,39 @@ class ValueExpression(object): > Val =3D Warn.result > return Val > > # A [ > B]* > def _RelExpr(self): >- return self._ExprFuncTemplate(self._AddExpr, ["<=3D", ">=3D", "<"= , ">", "LE", >"GE", "LT", "GT"]) >+ return self._ExprFuncTemplate(self._ShiftExpr, ["<=3D", ">=3D", "= <", ">", >"LE", "GE", "LT", "GT"]) >+ >+ def _ShiftExpr(self): >+ return self._ExprFuncTemplate(self._AddExpr, ["<<", ">>"]) > > # A [ + B]* > def _AddExpr(self): >- return self._ExprFuncTemplate(self._UnaryExpr, ["+", "-"]) >+ return self._ExprFuncTemplate(self._MulExpr, ["+", "-"]) >+ >+ # A [ * B]* >+ def _MulExpr(self): >+ return self._ExprFuncTemplate(self._UnaryExpr, ["*", "/", "%"]) > > # [!]*A > def _UnaryExpr(self): > if self._IsOperator(["!", "NOT", "not"]): > Val =3D self._UnaryExpr() > try: > return self.Eval('not', Val) > except WrnExpression, Warn: > self._WarnExcept =3D Warn > return Warn.result >+ if self._IsOperator(["~"]): >+ Val =3D self._UnaryExpr() >+ try: >+ return self.Eval('~', Val) >+ except WrnExpression, Warn: >+ self._WarnExcept =3D Warn >+ return Warn.result > return self._IdenExpr() > > # Parse identifier or encapsulated expression > def _IdenExpr(self): > Tk =3D self._GetToken() >@@ -535,11 +553,11 @@ class ValueExpression(object): > def _GetToken(self): > return self.__GetNList() > > @staticmethod > def __IsIdChar(Ch): >- return Ch in '._/:' or Ch.isalnum() >+ return Ch in '._:' or Ch.isalnum() > > # Parse operand > def _GetSingleToken(self): > self.__SkipWS() > Expr =3D self._Expr[self._Idx:] >-- >2.6.1.windows.1